Skip to content

Commit

Permalink
bug #22183 [Process] Fix bug which wiped or mangled env vars (pjcdawk…
Browse files Browse the repository at this point in the history
…ins)

This PR was squashed before being merged into the 3.2 branch (closes #22183).

Discussion
----------

[Process] Fix bug which wiped or mangled env vars

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

Fixing (and testing) a one-character bug introduced in a recent commit symfony/process@7d21c4a

Commits
-------

9439237 [Process] Fix bug which wiped or mangled env vars
  • Loading branch information
fabpot committed Mar 27, 2017
2 parents 56d4769 + 9439237 commit da7893a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/Process.php
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Process/Tests/ProcessTest.php
Expand Up @@ -1403,6 +1403,20 @@ public function testSetBadEnv()
$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'));
Expand Down

0 comments on commit da7893a

Please sign in to comment.