mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 13:32:18 +00:00
fix(hooks): read $$ as the process ID before looking for $'...'
In `echo $$'\'; npm run dev`, Bash reads `$$` as the process-ID parameter and the quote after it as an ordinary single quote, so it runs `npm run dev`. The splitter took the second `$` as the start of ANSI-C quoting, which hid the semicolon, and a here-document delimiter such as `$$'EOF'` was read as `$EOF`, so the body never ended. Consume the `$$` pair first in both places.
This commit is contained in:
3 files changed
+45
No files matched your search
@@ -49,6 +49,12 @@ function readWord(command, start) {
|
||||
let i = start;
|
||||
for (; i < command.length; i++) {
|
||||
const ch = command[i];
|
||||
// $$ is the process-ID parameter, so a quote right after it is not $'...'
|
||||
if (!quote && ch === '$' && command[i + 1] === '$') {
|
||||
word += '$$';
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
ANSI_C_QUOTED_RE.lastIndex = i;
|
||||
const ansiC = !quote && ch === '$' ? ANSI_C_QUOTED_RE.exec(command) : null;
|
||||
if (quote) {
|
||||
@@ -261,6 +267,13 @@ function splitShellSegments(command) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// $$ is the process-ID parameter, so a quote right after it is not $'...'
|
||||
if (ch === '$' && command[i + 1] === '$') {
|
||||
current += '$$';
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Opening quote. Keep ANSI-C quoting distinct from literal single quotes.
|
||||
if (ch === '$' && command[i + 1] === "'") {
|
||||
quote = "$'";
|
||||
|
||||
Reference in new issue
Block a user