From 61a2673ed2a0850bde62a365d394fc986754cab7 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 27 Mar 2017 17:26:57 +0100 Subject: [PATCH 1/3] [Process] Test showing that env backup wipes existing env vars --- .../Component/Process/Tests/ProcessTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index c51a116e7319f..3e1e754821103 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -1403,6 +1403,20 @@ public function testSetBadEnv() $this->assertSame('', $process->getErrorOutput()); } + public function testEnvBackupDoesNotDeleteExistingVars() + { + putenv('existing_var=foo'); + $process = $this->getProcess('echo "$new_test_var"'); + $process->setEnv(array('existing_var' => 'bar', 'new_test_var' => 'foo')); + $process->inheritEnvironmentVariables(); + + $process->run(); + + $this->assertSame('foo'.PHP_EOL, $process->getOutput()); + $this->assertSame('foo', getenv('existing_var')); + $this->assertFalse(getenv('new_test_var')); + } + public function testInheritEnvEnabled() { $process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('echo serialize($_SERVER);'), null, array('BAR' => 'BAZ')); From 8e220b43702d41f59638bcd09af074217f7dd353 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 27 Mar 2017 17:16:12 +0100 Subject: [PATCH 2/3] [Process] Fix bug which wiped or mangled env vars --- src/Symfony/Component/Process/Process.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 504b4c3bc567d..bd00e1761c574 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -277,7 +277,7 @@ public function start(callable $callback = null) } foreach ($env as $k => $v) { - $envBackup[$k] = getenv($v); + $envBackup[$k] = getenv($k); putenv(false === $v || null === $v ? $k : "$k=$v"); } $env = null; From 0622602de8e1c0df9323d032b52f0bb6a829deb9 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 27 Mar 2017 18:21:47 +0100 Subject: [PATCH 3/3] [Process] Fix env var test for Windows --- src/Symfony/Component/Process/Tests/ProcessTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 3e1e754821103..379dae2df717a 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -1406,13 +1406,13 @@ public function testSetBadEnv() public function testEnvBackupDoesNotDeleteExistingVars() { putenv('existing_var=foo'); - $process = $this->getProcess('echo "$new_test_var"'); + $process = $this->getProcess('php -r "echo getenv(\'new_test_var\');"'); $process->setEnv(array('existing_var' => 'bar', 'new_test_var' => 'foo')); $process->inheritEnvironmentVariables(); $process->run(); - $this->assertSame('foo'.PHP_EOL, $process->getOutput()); + $this->assertSame('foo', $process->getOutput()); $this->assertSame('foo', getenv('existing_var')); $this->assertFalse(getenv('new_test_var')); }