Skip to content

Commit e631cca

Browse files
committed
cleaned up escaping in ProcessBuilder
1 parent 0efca36 commit e631cca

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

src/Assetic/Filter/CompassFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public function filterLoad(AssetInterface $asset)
241241
$pb->add('--config')->add($this->config);
242242
}
243243

244-
$pb->add('--sass-dir')->add('""')->add('--css-dir')->add('""');
244+
$pb->add('--sass-dir')->add('')->add('--css-dir')->add('');
245245

246246
// compass choose the type (sass or scss from the filename)
247247
if (null !== $this->scss) {

src/Assetic/Util/ProcessBuilder.php

+8-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class ProcessBuilder
2525
private $timeout = 60;
2626
private $options = array();
2727
private $inheritEnv = false;
28-
private $escaper;
2928

3029
public function add($part)
3130
{
@@ -80,22 +79,18 @@ public function setOption($name, $value)
8079
return $this;
8180
}
8281

83-
public function setEscaper(\Closure $escaper)
84-
{
85-
$this->escaper = $escaper;
86-
87-
return $this;
88-
}
89-
9082
public function getProcess()
9183
{
92-
$escaper = $this->escaper ?: function($value)
93-
{
94-
return false === strpos($value, ' ') ? $value : escapeshellarg($value);
95-
};
84+
if (!count($this->parts)) {
85+
throw new \LogicException('You must add() command parts before calling getProcess().');
86+
}
87+
88+
$parts = $this->parts;
89+
$cmd = array_shift($parts);
90+
$script = escapeshellcmd($cmd).' '.implode(' ', array_map('escapeshellarg', $parts));
9691

9792
$env = $this->inheritEnv ? ($this->env ?: array()) + $_ENV : $this->env;
9893

99-
return new Process(implode(' ', array_map($escaper, $this->parts)), $this->cwd, $env, $this->stdin, $this->timeout, $this->options);
94+
return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $this->options);
10095
}
10196
}

tests/Assetic/Test/Util/ProcessBuilderTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function shouldInheritEnvironmentVars()
2424
$_ENV = $expected = array('foo' => 'bar');
2525

2626
$pb = new ProcessBuilder();
27-
$pb->inheritEnvironmentVariables();
27+
$pb->add('foo')->inheritEnvironmentVariables();
2828
$proc = $pb->getProcess();
2929

3030
$this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');
@@ -42,8 +42,11 @@ public function shouldNotReplaceExplicitlySetVars()
4242
$expected = array('foo' => 'baz');
4343

4444
$pb = new ProcessBuilder();
45-
$pb->setEnv('foo', 'baz');
46-
$pb->inheritEnvironmentVariables();
45+
$pb
46+
->setEnv('foo', 'baz')
47+
->inheritEnvironmentVariables()
48+
->add('foo')
49+
;
4750
$proc = $pb->getProcess();
4851

4952
$this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');

0 commit comments

Comments
 (0)