Skip to content

Commit f24a828

Browse files
bug symfony#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 | symfony#25564 | License | MIT | Doc PR | - Commits ------- 03adce2 [Process] Fix setting empty env vars
2 parents 2938a70 + 03adce2 commit f24a828

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,16 @@ public function start(callable $callback = null/*, array $env = array()*/)
326326
// @see : https://bugs.php.net/69442
327327
$ptsWorkaround = fopen(__FILE__, 'r');
328328
}
329+
if (defined('HHVM_VERSION')) {
330+
$envPairs = $env;
331+
} else {
332+
$envPairs = array();
333+
foreach ($env as $k => $v) {
334+
$envPairs[] = $k.'='.$v;
335+
}
336+
}
329337

330-
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $env, $this->options);
338+
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);
331339

332340
if (!is_resource($this->process)) {
333341
throw new RuntimeException('Unable to launch a new process.');

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,14 +1423,14 @@ public function testEnvBackupDoesNotDeleteExistingVars()
14231423

14241424
public function testEnvIsInherited()
14251425
{
1426-
$process = $this->getProcessForCode('echo serialize($_SERVER);', null, array('BAR' => 'BAZ'));
1426+
$process = $this->getProcessForCode('echo serialize($_SERVER);', null, array('BAR' => 'BAZ', 'EMPTY' => ''));
14271427

14281428
putenv('FOO=BAR');
14291429
$_ENV['FOO'] = 'BAR';
14301430

14311431
$process->run();
14321432

1433-
$expected = array('BAR' => 'BAZ', 'FOO' => 'BAR');
1433+
$expected = array('BAR' => 'BAZ', 'EMPTY' => '', 'FOO' => 'BAR');
14341434
$env = array_intersect_key(unserialize($process->getOutput()), $expected);
14351435

14361436
$this->assertEquals($expected, $env);
@@ -1511,7 +1511,7 @@ public function testRawCommandLine()
15111511
)
15121512
15131513
EOTXT;
1514-
$this->assertSame($expected, $p->getOutput());
1514+
$this->assertSame($expected, str_replace('Standard input code', '-', $p->getOutput()));
15151515
}
15161516

15171517
public function provideEscapeArgument()

0 commit comments

Comments
 (0)