8000 merged branch oodle/ticket_7196 (PR #8227) · egeloen/symfony@6089f32 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6089f32

Browse files
committed
merged branch oodle/ticket_7196 (PR symfony#8227)
This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes symfony#8227). Discussion ---------- [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 ``` | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | 7196 | License | MIT | Doc PR | none ``` Commits ------- 2c6af95 [Process] fix issue where $_ENV contains array vals
2 parents c27735d + 8764944 commit 6089f32

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
@@ -151,6 +151,9 @@ public function getProcess()
151151
$env = $this->env;
152152
}
153153

154+
// Process can not handle env values that are arrays
155+
$env = $env ? array_filter($env, function ($value) { if (!is_array($value)) { return true; } }) : $env;
156+
154157
return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options);
155158
}
156159
}

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