8000 [Process] fix issue where $_ENV contains array vals · stloyd/symfony@2c6af95 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c6af95

Browse files
committed
[Process] fix issue where $_ENV contains array vals
There are cases where $env or $_ENV can contain a value that is an array This will cause Process to throw an Array to String conversion exception Initially I submitted a patch of Process.php, however Fabien indicated that it shouldn't be fixed there (see below pull request). Before recently, a simple work around would be in php.ini to set: register_argc_argv = On However with recent changes, this seems to no longer work. Original pull request: symfony#7354 See ticket symfony#7196
1 parent ea913e0 commit 2c6af95

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Symfony/Component/Process/ProcessBuilder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ public function getProcess()
169169
$env = $this->env;
170170
}
171171

172+
// Process can not handle env values that are arrays
173+
$env = $env ? array_filter($env, function ($value) { if (!is_array($value)) { return true; } }) : $env;
174+
172175
return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options);
173176
}
174177
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ public function testProcessShouldInheritAndOverrideEnvironmentVars()
4545
$_ENV = $snapshot;
4646
}
4747

48+
public function testProcessBuilderShouldNotPassEnvArrays()
49+
{
50+
$snapshot = $_ENV;
51+
$_ENV = array('a' => array('b', 'c'), 'd' => 'e', 'f' => 'g');
52+
$expected = array('d' => 'e', 'f' => 'g');
53+
54+
$pb = new ProcessBuilder();
55+
$pb->add('a')->inheritEnvironmentVariables()
56+
->setEnv('d', 'e');
57+
$proc = $pb->getProcess();
58+
59+
$this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() removes array values from $_ENV');
60+
61+
$_ENV = $snapshot;
62+
}
63+
4864
public function testInheritEnvironmentVarsByDefault()
4965
{
5066
$pb = new ProcessBuilder();

0 commit comments

Comments
 (0)
0