8000 bug #22551 [Process] Ecaping of CLI arguments containing slashes on W… · symfony/symfony@288d55f · GitHub
[go: up one dir, main page]

Skip to content

Commit 288d55f

Browse files
committed
bug #22551 [Process] Ecaping of CLI arguments containing slashes on Windows (maryo)
This PR was squashed before being merged into the 3.3-dev branch (closes #22551). Discussion ---------- [Process] Ecaping of CLI arguments containing slashes on Windows | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22549 | License | MIT Actually only the first argument - the command needs to be escaped but that would need another condition. I think it should be OK. Commits ------- 0d07312 [Process] Ecaping of CLI arguments containing slashes on Windows
2 parents 89979ca + 0d07312 commit 288d55f

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ private function escapeArgument($argument)
17171717
if (false !== strpos($argument, "\0")) {
17181718
$argument = str_replace("\0", '?', $argument);
17191719
}
1720-
if (!preg_match('/[()%!^"<>&|\s]/', $argument)) {
1720+
if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) {
17211721
return $argument;
17221722
}
17231723
$argument = preg_replace('/(\\\\+)$/', '$1$1', $argument);

src/Symfony/Component/Process/Tests/ProcessBuilderTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ public function testPrefixIsPrependedToAllGeneratedProcess()
9191

9292
$proc = $pb->setArguments(array('-v'))->getProcess();
9393
if ('\\' === DIRECTORY_SEPARATOR) {
94-
$this->assertEquals('/usr/bin/php -v', $proc->getCommandLine());
94+
$this->assertEquals('"/usr/bin/php" -v', $proc->getCommandLine());
9595
} else {
9696
$this->assertEquals("'/usr/bin/php' '-v'", $proc->getCommandLine());
9797
}
9898

9999
$proc = $pb->setArguments(array('-i'))->getProcess();
100100
if ('\\' === DIRECTORY_SEPARATOR) {
101-
$this->assertEquals('/usr/bin/php -i', $proc->getCommandLine());
101+
$this->assertEquals('"/usr/bin/php" -i', $proc->getCommandLine());
102102
} else {
103103
$this->assertEquals("'/usr/bin/php' '-i'", $proc->getCommandLine());
104104
}
@@ -111,14 +111,14 @@ public function testArrayPrefixesArePrependedToAllGeneratedProcess()
111111

112112
$proc = $pb->setArguments(array('-v'))->getProcess();
113113
if ('\\' === DIRECTORY_SEPARATOR) {
114-
$this->assertEquals('/usr/bin/php composer.phar -v', $proc->getCommandLine());
114+
$this->assertEquals('"/usr/bin/php" composer.phar -v', $proc->getCommandLine());
115115
} else {
116116
$this->assertEquals("'/usr/bin/php' 'composer.phar' '-v'", $proc->getCommandLine());
117117
}
118118

119119
$proc = $pb->setArguments(array('-i'))->getProcess();
120120
if ('\\' === DIRECTORY_SEPARATOR) {
121-
$this->assertEquals('/usr/bin/php composer.phar -i', $proc->getCommandLine());
121+
$this->assertEquals('"/usr/bin/php" composer.phar -i', $proc->getCommandLine());
122122
} else {
123123
$this->assertEquals("'/usr/bin/php' 'composer.phar' '-i'", $proc->getCommandLine());
124124
}
@@ -164,7 +164,7 @@ public function testShouldNotThrowALogicExceptionIfNoArgument()
164164
->getProcess();
165165

166166
if ('\\' === DIRECTORY_SEPARATOR) {
167-
$this->assertEquals('/usr/bin/php', $process->getCommandLine());
167+
$this->assertEquals('"/usr/bin/php"', $process->getCommandLine());
168168
} else {
169169
$this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
170170
}
@@ -176,7 +176,7 @@ public function testShouldNotThrowALogicExceptionIfNoPrefix()
176176
->getProcess();
177177

178178
if ('\\' === DIRECTORY_SEPARATOR) {
179-
$this->assertEquals('/usr/bin/php', $process->getCommandLine());
179+
$this->assertEquals('"/usr/bin/php"', $process->getCommandLine());
180180
} else {
181181
$this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
182182
}

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,8 @@ public function testRestart()
715715
// Ensure that both processed finished and the output is numeric
716716
$this->assertFalse($process1->isRunning());
717717
$this->assertFalse($process2->isRunning());
718-
$this->assertTrue(is_numeric($process1->getOutput()));
719-
$this->assertTrue(is_numeric($process2->getOutput()));
718+
$this->assertInternalType('numeric', $process1->getOutput());
719+
$this->assertInternalType('numeric', $process2->getOutput());
720720

721721
// Ensure that restart returned a new process by check that the output is different
722722
$this->assertNotEquals($process1->getOutput(), $process2->getOutput());
@@ -1446,6 +1446,14 @@ public function testInheritEnvDisabled()
14461446
$this->assertSame($expected, $env);
14471447
}
14481448

1449+
public function testGetCommandLine()
1450+
{
1451+
$p = new Process(array('/usr/bin/php'));
1452+
1453+
$expected = '\\' === DIRECTORY_SEPARATOR ? '"/usr/bin/php"' : "'/usr/bin/php'";
1454+
$this->assertSame($expected, $p->getCommandLine());
1455+
}
1456+
14491457
/**
14501458
* @dataProvider provideEscapeArgument
14511459
*/

0 commit comments

Comments
 (0)
0