From 8764944c69d3afbd0ee19d2b200f4f1f28211ee4 Mon Sep 17 00:00:00 2001 From: Matthew J Mucklo Date: Fri, 7 Jun 2013 14:35:54 -0700 Subject: [PATCH] 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: https://github.com/symfony/symfony/pull/7354 See ticket https://github.com/symfony/symfony/issues/7196 --- src/Symfony/Component/Process/ProcessBuilder.php | 3 +++ .../Process/Tests/ProcessBuilderTest.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Symfony/Component/Process/ProcessBuilder.php b/src/Symfony/Component/Process/ProcessBuilder.php index c4ef31d3112e..151340d336e4 100644 --- a/src/Symfony/Component/Process/ProcessBuilder.php +++ b/src/Symfony/Component/Process/ProcessBuilder.php @@ -151,6 +151,9 @@ public function getProcess() $env = $this->env; } + // 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); } } diff --git a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php index 53e403605b45..1d46d71a57de 100644 --- a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php @@ -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();