mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 13:32:18 +00:00
fix(hooks): read NUL-ended delimiters, Bash blanks before #, and long bodies
Bash ends a decoded $'...' string at its first NUL, so `cat <<$'EOF\0X'` ends at the line EOF, but the splitter looked for EOF\0X and swallowed the commands after the body. A carriage return or a no-break space is not a blank to Bash, so `echo foo\r# && npm run dev` runs the dev server, but the splitter read the # as a comment. And spreading a long substitution's segments into push() threw RangeError, which the hook's catch turned into an allow. Truncate the decoded part at the NUL, use Bash's blanks for word starts, and append the segments one at a time.
This commit is contained in:
4 files changed
+35
-4
No files matched your search
@@ -204,8 +204,12 @@ function collectCheckSegments(cmd) {
|
||||
|
||||
for (const body of [...extractCommandSubstitutions(current), ...extractSubshellGroups(current)]) {
|
||||
const bodySegments = splitShellSegments(body);
|
||||
segments.push(...bodySegments);
|
||||
queue.push(body, ...bodySegments);
|
||||
// One at a time: spreading a long command's segments into push() exceeds the argument limit.
|
||||
queue.push(body);
|
||||
for (const segment of bodySegments) {
|
||||
segments.push(segment);
|
||||
queue.push(segment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,8 @@ function readWord(command, start) {
|
||||
// $'...' decodes its escapes, so $'E\x4fF' is EOF
|
||||
const decoded = decodeAnsiC(ansiC[1]);
|
||||
if (decoded === null) utf8 = false;
|
||||
else word += decoded;
|
||||
// Bash ends the decoded string at a NUL, so $'EOF\0X' is EOF
|
||||
else word += decoded.split('\0', 1)[0];
|
||||
quoted = true;
|
||||
i += ansiC[0].length - 1;
|
||||
} else if (ch === "'" || ch === '"') {
|
||||
@@ -165,7 +166,8 @@ function startsWord(command, index, current) {
|
||||
while (before >= 1 && command[before] === '\n' && command[before - 1] === '\\' && !isEscaped(command, before - 1)) {
|
||||
before -= 2;
|
||||
}
|
||||
return before < 0 || (/[\s;&|(]/.test(command[before]) && !isEscaped(command, before));
|
||||
// Bash's blanks are a space and a tab; a carriage return or a no-break space is part of a word.
|
||||
return before < 0 || (/[ \t\n;&|(]/.test(command[before]) && !isEscaped(command, before));
|
||||
}
|
||||
|
||||
// The end of a span copied as is, or -1: a comment, which runs to the end of its line, or an
|
||||
|
||||
Reference in new issue
Block a user