diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index cc97cef8648a0..81a5681c0deae 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -269,7 +269,8 @@ public function start(callable $callback = null, array $env = array()) // exec is mandatory to deal with sending a signal to the process $commandline = 'exec '.$commandline; } - } else { + } elseif ('!' === substr($commandline = trim($commandline), 0, 1)) { + $commandline = ltrim(substr($commandline, 1)); $commandline = $this->replacePlaceholders($commandline, $env); } @@ -1554,7 +1555,11 @@ private function escapeArgument(string $argument): string private function replacePlaceholders(string $commandline, array $env) { - $pattern = '\\' === DIRECTORY_SEPARATOR ? '!%s!' : '${%s}'; + if (false !== strpos($commandline, '"')) { + throw new InvalidArgumentException(sprintf('Double quotes are invalid in prepared command line: !%s', $commandline)); + } + + $pattern = '\\' === DIRECTORY_SEPARATOR ? '!%s!' : '"$%s"'; return preg_replace_callback('/\{\{ ?([_a-zA-Z0-9]++) ?\}\}/', function ($m) use ($pattern, $commandline, $env) { if (!isset($env[$m[1]]) || false === $env[$m[1]]) { diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 2acf3fadecabe..f12dc8055f325 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -1380,13 +1380,13 @@ public function testChainedProcesses() public function testSetBadEnv() { - $process = $this->getProcess('echo hello'); + $process = $this->getProcess('echo {{ hello }}'); $process->setEnv(array('bad%%' => '123')); $process->inheritEnvironmentVariables(true); $process->run(); - $this->assertSame('hello'.PHP_EOL, $process->getOutput()); + $this->assertSame('{{ hello }}'.PHP_EOL, $process->getOutput()); $this->assertSame('', $process->getErrorOutput()); } @@ -1476,7 +1476,7 @@ public function provideEscapeArgument() public function testPreparedCommand() { - $p = new Process('echo {{ abc }}DEF'); + $p = new Process('!echo {{ abc }}DEF'); $p->run(null, array('abc' => 'ABC')); $this->assertSame('ABCDEF', rtrim($p->getOutput())); @@ -1488,7 +1488,7 @@ public function testPreparedCommand() */ public function testPreparedCommandWithMissingValue() { - $p = new Process('echo {{ abc }}'); + $p = new Process('!echo {{ abc }}'); $p->run(null, array('bcd' => 'BCD')); } @@ -1498,7 +1498,17 @@ public function testPreparedCommandWithMissingValue() */ public function testPreparedCommandWithNoValues() { - $p = new Process('echo {{ abc }}'); + $p = new Process('!echo {{ abc }}'); + $p->run(); + } + + /** + * @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException + * @expectedExceptionMessage Double quotes are invalid in prepared command line: !echo "{{ abc }}" + */ + public function testPreparedCommandWithDoubleQuote() + { + $p = new Process('!echo "{{ abc }}"'); $p->run(); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy