8000 [Process] Fixed issue where $env or $_ENV can contain array values by mmucklo · Pull Request #8123 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Process] Fixed issue where $env or $_ENV can contain array values #8123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Prev Previous commit
Next Next commit
[Process] fix issue where env contains array vals
See ticket #7196
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 to set:

  register_argc_argv = On

in php.ini, however with recent changes, this seems to no longer work.

Original pull request: #7354
  • Loading branch information
mmucklo committed May 23, 2013
commit 6ceb4c368d5ff26b25919e1478a5b8002db9450e
3 changes: 3 additions & 0 deletions src/Symfony/Component/Process/ProcessBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public function getProcess()
$env = $this->env;
}
8000
// Process can not handle env values that are arrays
$env = $env ? array_filter($env, function ($value) { if (!is_array($value)) { return true; } }) : $env;

return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options);
}
}
16 changes: 16 additions & 0 deletions src/Symfony/Component/Process/Tests/ProcessBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ public function testProcessShouldInheritAndOverrideEnvironmentVars()
$_ENV = $snapshot;
}

public function testProcessBuilderShouldNotPassEnvArrays()
{
$snapshot = $_ENV;
$_ENV = array('a' => array('b', 'c'), 'd' => 'e', 'f' => 'g');
$expected = array('d' => 'e', 'f' => 'g');

$pb = new ProcessBuilder();
$pb->add('a')->inheritEnvironmentVariables()
->setEnv('d', 'e');
$proc = $pb->getProcess();

$this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() removes array values from $_ENV');

$_ENV = $snapshot;
}

public function testInheritEnvironmentVarsByDefault()
{
$pb = new ProcessBuilder();
Expand Down
0