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:
L4XB committed 2026-11-05 10:27:19 +01:00
1 parent 7a0188db61
commit 80a26c2ceb
3 files changed
+45

No files matched your search

+13
View File
@@ -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 = "$'";