Skip to content

Commit

Permalink
[Process] Use new ProcessUtils::escapeArgument to escape ProcessBuild…
Browse files Browse the repository at this point in the history
…er prefix
  • Loading branch information
romainneutron committed Apr 23, 2013
1 parent 04b4f33 commit 6e1fe78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ProcessBuilder.php
Expand Up @@ -160,8 +160,8 @@ public function getProcess()

$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;
Expand Down
13 changes: 13 additions & 0 deletions Tests/ProcessBuilderTest.php
Expand Up @@ -139,4 +139,17 @@ public function testShouldEscapeArguments()
$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());
}
}
}

0 comments on commit 6e1fe78

Please sign in to comment.