[Process] Use new ProcessUtils::escapeArgument to escape ProcessBuilder prefix

This commit is contained in:
Romain Neutron 2013-04-23 22:48:37 +02:00
parent 61c56fc54a
commit 209799b18e
2 changed files with 15 additions and 2 deletions

View File

@ -160,8 +160,8 @@ class ProcessBuilder
$options = $this->options;
$script = ($this->prefix ? escapeshellarg($this->prefix) . ' ' : '')
.implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $this->arguments));
$arguments = $this->prefix ? array_merge(array($this->prefix), $this->arguments) : $this->arguments;
$script = implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $arguments));
if ($this->inheritEnv) {
$env = $this->env ? $this->env + $_ENV : null;

View File

@ -139,4 +139,17 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
$this->assertSame("'%path%' 'foo \" bar'", $proc->getCommandLine());
}
}
public function testShouldEscapeArgumentsAndPrefix()
{
$pb = new ProcessBuilder(array('arg'));
$pb->setPrefix('%prefix%');
$proc = $pb->getProcess();
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->assertSame('^%"prefix"^% "arg"', $proc->getCommandLine());
} else {
$this->assertSame("'%prefix%' 'arg'", $proc->getCommandLine());
}
}
}