From c2c146dc6a053a91c67562bef8152e14d839b172 Mon Sep 17 00:00:00 2001 From: Simon Leblanc Date: Wed, 21 Dec 2016 00:32:59 +0100 Subject: [PATCH 1/2] Fix environment merge from server var --- src/Assetic/Filter/BaseProcessFilter.php | 3 +++ .../Assetic/Test/Filter/CompassFilterTest.php | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Assetic/Filter/BaseProcessFilter.php b/src/Assetic/Filter/BaseProcessFilter.php index 642495ab4..c15bd9c6c 100644 --- a/src/Assetic/Filter/BaseProcessFilter.php +++ b/src/Assetic/Filter/BaseProcessFilter.php @@ -51,6 +51,9 @@ protected function createProcessBuilder(array $arguments = array()) protected function mergeEnv(ProcessBuilder $pb) { foreach (array_filter($_SERVER, 'is_scalar') as $key => $value) { + if (preg_match('/^[a-z][a-z0-9_]*$/i', $key) === 0) { + continue; + } $pb->setEnv($key, $value); } } diff --git a/tests/Assetic/Test/Filter/CompassFilterTest.php b/tests/Assetic/Test/Filter/CompassFilterTest.php index 25e2fc5a9..d6e4c8937 100644 --- a/tests/Assetic/Test/Filter/CompassFilterTest.php +++ b/tests/Assetic/Test/Filter/CompassFilterTest.php @@ -69,4 +69,24 @@ public function testCompassMixin() $this->assertContains('text-decoration', $asset->getContent()); } + + public function testEnvironment() + { + $_SERVER = [ + 'GOOD_ENV_VAR' => 'scalar', + 'NOT_SCALAR_VAR' => [], + 'good_minus_env_var' => 'scalar', + 'bad-env-bar' => 'scalar', + '3_BAD_NUMBER_ENV_VAR' => 'scalar', + 'BAD_$CHARACTER_ENV_VAR' => 'scalar', + 'GOD_NUMBER_3_ENV_VAR' => 'scalar', + ]; + + $asset = new FileAsset(__DIR__.'/fixtures/compass/stylesheet.sass'); + $asset->load(); + + $this->filter->filterLoad($asset); + + $this->assertContains('.test-class', $asset->getContent()); + } } From 7f47c7d25e13214c3d2b968844c2a428964ea85d Mon Sep 17 00:00:00 2001 From: Simon Leblanc Date: Wed, 21 Dec 2016 00:54:19 +0100 Subject: [PATCH 2/2] Compatibility with PHP 5.3 --- tests/Assetic/Test/Filter/CompassFilterTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Assetic/Test/Filter/CompassFilterTest.php b/tests/Assetic/Test/Filter/CompassFilterTest.php index d6e4c8937..55517ccd1 100644 --- a/tests/Assetic/Test/Filter/CompassFilterTest.php +++ b/tests/Assetic/Test/Filter/CompassFilterTest.php @@ -72,15 +72,15 @@ public function testCompassMixin() public function testEnvironment() { - $_SERVER = [ + $_SERVER = array( 'GOOD_ENV_VAR' => 'scalar', - 'NOT_SCALAR_VAR' => [], + 'NOT_SCALAR_VAR' => array(), 'good_minus_env_var' => 'scalar', 'bad-env-bar' => 'scalar', '3_BAD_NUMBER_ENV_VAR' => 'scalar', 'BAD_$CHARACTER_ENV_VAR' => 'scalar', 'GOD_NUMBER_3_ENV_VAR' => 'scalar', - ]; + ); $asset = new FileAsset(__DIR__.'/fixtures/compass/stylesheet.sass'); $asset->load();