Skip to content

Commit c6ac7e3

Browse files
update
1 parent db4a6d3 commit c6ac7e3

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

Capsule/Artisan.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct()
6161
public static function call(string $input): int
6262
{
6363
// Tokenize input and drop placeholder tokens like [name]
64-
$tokens = self::tokenize($input);
64+
$tokens = self::tokenizeCommand($input);
6565
$tokens = array_values(array_filter($tokens, static function ($t) {
6666
return !preg_match('/^\[[^\]]+\]$/', (string)$t);
6767
}));
@@ -75,6 +75,34 @@ public static function call(string $input): int
7575
return $artisan->run($argv);
7676
}
7777

78+
/**
79+
* Split a command string into tokens while respecting quotes.
80+
*/
81+
private static function tokenizeCommand(string $input): array
82+
{
83+
$input = trim($input);
84+
if ($input === '') {
85+
return [];
86+
}
87+
88+
$tokens = [];
89+
// Match: "double-quoted" | 'single-quoted' | unquoted\-chunks
90+
$pattern = '/"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|(\\S+)/';
91+
if (preg_match_all($pattern, $input, $matches, PREG_SET_ORDER)) {
92+
foreach ($matches as $m) {
93+
if (($m[1] ?? '') !== '') {
94+
$tokens[] = stripcslashes($m[1]);
95+
} elseif (($m[2] ?? '') !== '') {
96+
$tokens[] = stripcslashes($m[2]);
97+
} else {
98+
$tokens[] = $m[3];
99+
}
100+
}
101+
}
102+
103+
return $tokens;
104+
}
105+
78106
/**
79107
* Register a command by name with description
80108
*

Capsule/Traits/ArtisanDiscovery.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,7 @@ trait ArtisanDiscovery
2828
private static array $registeredProviders = [];
2929

3030

31-
/**
32-
* Split a command string into tokens while respecting quotes.
33-
*/
34-
private static function tokenize(string $input): array
35-
{
36-
$input = trim($input);
37-
if ($input === '') {
38-
return [];
39-
}
4031

41-
$tokens = [];
42-
$pattern = '/"([^"\\]*(?:\\.[^"\\]*)*)"|\'([^\'\\]*(?:\\.[^\'\\]*)*)\'|(\S+)/';
43-
if (preg_match_all($pattern, $input, $matches, PREG_SET_ORDER)) {
44-
foreach ($matches as $m) {
45-
if (($m[1] ?? '') !== '') {
46-
$tokens[] = stripcslashes($m[1]);
47-
} elseif (($m[2] ?? '') !== '') {
48-
$tokens[] = stripcslashes($m[2]);
49-
} else {
50-
$tokens[] = $m[3];
51-
}
52-
}
53-
}
54-
55-
return $tokens;
56-
}
5732

5833
/**
5934
* Discover providers by scanning vendor composer.json

0 commit comments

Comments
 (0)