mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 21:42:11 +00:00
fix(hooks): compare ANSI-C delimiter bytes exactly and decode them without spreading
Invalid UTF-8 in a $'...' delimiter became U+FFFD, which a body line could match although Bash compares raw bytes. Such a delimiter now matches no line, so its body runs to the end of the command, as in Bash. The bytes were also spread into one push() call, which threw for a delimiter of 200,000 characters. The hook then failed open. The bytes are now collected as buffers and concatenated once.
This commit is contained in:
2 files changed
+24
-9
No files matched your search
@@ -147,6 +147,11 @@ test('a here-document delimiter is a shell word, read without its quotes', () =>
|
||||
// Hex and octal escapes are bytes, so both of these are the UTF-8 delimiter é
|
||||
assert.deepStrictEqual(splitShellSegments("cat <<$'\\xc3\\xa9'\n\u00c3\u00a9\nnpm run dev\n\u00e9\nls"), ["cat <<$'\\xc3\\xa9'", 'ls']);
|
||||
assert.deepStrictEqual(splitShellSegments("cat <<$'\\303\\251'\nnpm run dev\n\u00e9\nls"), ["cat <<$'\\303\\251'", 'ls']);
|
||||
// A delimiter whose bytes are not UTF-8 matches no line, so the body runs to the end
|
||||
assert.deepStrictEqual(splitShellSegments("cat <<$'\\xff'\n\ufffd\nnpm run dev"), ["cat <<$'\\xff'"]);
|
||||
// A long delimiter is read in one pass
|
||||
const long = 'a'.repeat(200000);
|
||||
assert.deepStrictEqual(splitShellSegments(`cat <<$'${long}'\ntext\n${long}\nnpm run dev`), [`cat <<$'${long}'`, 'npm run dev']);
|
||||
// An empty delimiter ends the body at the first empty line
|
||||
assert.deepStrictEqual(splitShellSegments("cat <<''\nnpm run dev\n\nls"), ["cat <<''", 'ls']);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user