From 9439237c8130b6b648e30b8c0506ab8f830558b0 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 27 Mar 2017 17:26:57 +0100 Subject: [PATCH] [Process] Fix bug which wiped or mangled env vars --- src/Symfony/Component/Process/Process.php | 2 +- .../Component/Process/Tests/ProcessTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 504b4c3bc5..bd00e1761c 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -277,7 +277,7 @@ class Process implements \IteratorAggregate } foreach ($env as $k => $v) { - $envBackup[$k] = getenv($v); + $envBackup[$k] = getenv($k); putenv(false === $v || null === $v ? $k : "$k=$v"); } $env = null; diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index c51a116e73..379dae2df7 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -1403,6 +1403,20 @@ class ProcessTest extends TestCase $this->assertSame('', $process->getErrorOutput()); } + public function testEnvBackupDoesNotDeleteExistingVars() + { + putenv('existing_var=foo'); + $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', $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'));