bug #25567 [Process] Fix setting empty env vars (nicolas-grekas)
This PR was merged into the 3.3 branch.
Discussion
----------
[Process] Fix setting empty env vars
| Q | A
| ------------- | ---
| Branch? | 3.3
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #25564
| License | MIT
| Doc PR | -
Commits
-------
03adce2
[Process] Fix setting empty env vars
This commit is contained in:
commit
f24a828124
@ -326,8 +326,16 @@ class Process implements \IteratorAggregate
|
||||
// @see : https://bugs.php.net/69442
|
||||
$ptsWorkaround = fopen(__FILE__, 'r');
|
||||
}
|
||||
if (defined('HHVM_VERSION')) {
|
||||
$envPairs = $env;
|
||||
} else {
|
||||
$envPairs = array();
|
||||
foreach ($env as $k => $v) {
|
||||
$envPairs[] = $k.'='.$v;
|
||||
}
|
||||
}
|
||||
|
||||
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $env, $this->options);
|
||||
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);
|
||||
|
||||
if (!is_resource($this->process)) {
|
||||
throw new RuntimeException('Unable to launch a new process.');
|
||||
|
@ -1423,14 +1423,14 @@ class ProcessTest extends TestCase
|
||||
|
||||
public function testEnvIsInherited()
|
||||
{
|
||||
$process = $this->getProcessForCode('echo serialize($_SERVER);', null, array('BAR' => 'BAZ'));
|
||||
$process = $this->getProcessForCode('echo serialize($_SERVER);', null, array('BAR' => 'BAZ', 'EMPTY' => ''));
|
||||
|
||||
putenv('FOO=BAR');
|
||||
$_ENV['FOO'] = 'BAR';
|
||||
|
||||
$process->run();
|
||||
|
||||
$expected = array('BAR' => 'BAZ', 'FOO' => 'BAR');
|
||||
$expected = array('BAR' => 'BAZ', 'EMPTY' => '', 'FOO' => 'BAR');
|
||||
$env = array_intersect_key(unserialize($process->getOutput()), $expected);
|
||||
|
||||
$this->assertEquals($expected, $env);
|
||||
@ -1511,7 +1511,7 @@ Array
|
||||
)
|
||||
|
||||
EOTXT;
|
||||
$this->assertSame($expected, $p->getOutput());
|
||||
$this->assertSame($expected, str_replace('Standard input code', '-', $p->getOutput()));
|
||||
}
|
||||
|
||||
public function provideEscapeArgument()
|
||||
|
Reference in New Issue
Block a user