Skip to content

Commit 8af94f6

Browse files
committed
remove unnecessary space escape
1 parent bc46e8c commit 8af94f6

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/ChildProcess.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ public function start(string|array $cmd, string $alias, ?string $cwd = null, ?ar
1212
{
1313
$cwd = $cwd ?? base_path();
1414

15-
$cmd = is_iterable($cmd)
16-
// when an array is passed, escape spaces for each item
17-
? array_map(fn ($a) => str_replace(' ', '\ ', $a), $cmd)
18-
// when a string is passed, explode it on the space
19-
: array_values(array_filter(explode(' ', $cmd)));
15+
if (is_string($cmd)) {
16+
// When a string is passed, explode it on the space
17+
$cmd = array_values(array_filter(explode(' ', $cmd)));
18+
}
2019

2120
$this->client->post('child-process/start', [
2221
'alias' => $alias,

tests/ChildProcess/ChildProcessTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
Http::assertSent(function (Request $request) {
2727
return $request->url() === 'http://localhost:4000/api/child-process/start' &&
2828
$request['alias'] === 'some-alias' &&
29-
$request['cmd'] === [str_replace(' ', '\ ', PHP_BINARY), 'artisan', 'foo:bar'] &&
29+
$request['cmd'] === [PHP_BINARY, 'artisan', 'foo:bar'] &&
3030
$request['cwd'] === base_path() &&
3131
$request['env'] === ['baz' => 'zah'];
3232
});
@@ -44,10 +44,10 @@
4444

4545
it('accepts either a string or a array as artisan command argument', function () {
4646
ChildProcess::artisan('foo:bar', 'some-alias');
47-
Http::assertSent(fn (Request $request) => $request['cmd'] === [str_replace(' ', '\ ', PHP_BINARY), 'artisan', 'foo:bar']);
47+
Http::assertSent(fn (Request $request) => $request['cmd'] === [PHP_BINARY, 'artisan', 'foo:bar']);
4848

4949
ChildProcess::artisan(['foo:baz'], 'some-alias');
50-
Http::assertSent(fn (Request $request) => $request['cmd'] === [str_replace(' ', '\ ', PHP_BINARY), 'artisan', 'foo:baz']);
50+
Http::assertSent(fn (Request $request) => $request['cmd'] === [PHP_BINARY, 'artisan', 'foo:baz']);
5151
});
5252

5353
it('sets the cwd to the base path if none was given', function () {
@@ -63,11 +63,6 @@
6363
Http::assertSent(fn (Request $request) => $request['cmd'] === ['foo', 'bar', 'baz', 'bak']);
6464
});
6565

66-
it('escapes spaces when passing a command array', function () {
67-
ChildProcess::start(['path/to/some executable with spaces.sh', '--foo', '--bar'], 'some-alias');
68-
Http::assertSent(fn (Request $request) => $request['cmd'] === ['path/to/some\ executable\ with\ spaces.sh', '--foo', '--bar']);
69-
});
70-
7166
it('can stop a child process', function () {
7267
ChildProcess::stop('some-alias');
7368

0 commit comments

Comments
 (0)