Skip to content

Commit 6867f73

Browse files
authored
Escape PHP executable (#162)
1 parent 539f2f2 commit 6867f73

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/Input/ChildCommandFactory.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use function array_filter;
2020
use function array_map;
2121
use function array_merge;
22+
use function explode;
2223
use function Safe\getcwd;
2324
use function sprintf;
2425

@@ -64,7 +65,7 @@ private function createBaseCommand(
6465
InputInterface $input
6566
): array {
6667
return array_filter([
67-
$this->phpExecutable,
68+
...$this->getEscapedPhpExecutable(),
6869
$this->scriptPath,
6970
$this->commandName,
7071
...array_map('strval', self::getArguments($input)),
@@ -87,6 +88,14 @@ private function getForwardedOptions(InputInterface $input): array
8788
);
8889
}
8990

91+
/**
92+
* @return list<string>
93+
*/
94+
private function getEscapedPhpExecutable(): array
95+
{
96+
return explode(' ', $this->phpExecutable);
97+
}
98+
9099
/**
91100
* @return list<string|bool|int|float|null|array<string|bool|int|float|null>>
92101
*/

src/ParallelExecutorFactory.php

-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ public function withProgressSymbol(string $progressSymbol): self
320320
}
321321

322322
/**
323-
* TODO: although it is a string maybe it has additional options, ensure those are escaped
324323
* The path of the PHP executable. It is the executable that will be used
325324
* to spawn the child process(es).
326325
*/

tests/Input/ChildCommandFactoryTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,31 @@ public static function childProvider(): iterable
245245
],
246246
];
247247
})();
248+
249+
yield 'enriched PHP executable' => (static function () use (
250+
$scriptPath,
251+
$commandName
252+
) {
253+
[$input, $commandDefinition] = self::createInput(
254+
[],
255+
[],
256+
);
257+
258+
return [
259+
'/path/to/php -dmemory_limit=1',
260+
$scriptPath,
261+
$commandName,
262+
$commandDefinition,
263+
$input,
264+
[
265+
'/path/to/php',
266+
'-dmemory_limit=1',
267+
$scriptPath,
268+
$commandName,
269+
'--child',
270+
],
271+
];
272+
})();
248273
}
249274

250275
public function test_it_cannot_create_a_factory_with_an_invalid_script_path(): void

0 commit comments

Comments
 (0)