bug #22183 [Process] Fix bug which wiped or mangled env vars (pjcdawkins)
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 commit7d21c4a2cf
Commits -------9439237c81
[Process] Fix bug which wiped or mangled env vars
This commit is contained in:
commit
da7893a7bf
@ -277,7 +277,7 @@ class Process implements \IteratorAggregate
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($env as $k => $v) {
|
foreach ($env as $k => $v) {
|
||||||
$envBackup[$k] = getenv($v);
|
$envBackup[$k] = getenv($k);
|
||||||
putenv(false === $v || null === $v ? $k : "$k=$v");
|
putenv(false === $v || null === $v ? $k : "$k=$v");
|
||||||
}
|
}
|
||||||
$env = null;
|
$env = null;
|
||||||
|
@ -1403,6 +1403,20 @@ class ProcessTest extends TestCase
|
|||||||
$this->assertSame('', $process->getErrorOutput());
|
$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()
|
public function testInheritEnvEnabled()
|
||||||
{
|
{
|
||||||
$process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('echo serialize($_SERVER);'), null, array('BAR' => 'BAZ'));
|
$process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('echo serialize($_SERVER);'), null, array('BAR' => 'BAZ'));
|
||||||
|
Reference in New Issue
Block a user