Summary
shell-quote (reproduced on v1.10.0) does not implement bash's ANSI-C quoting — the $'...' form. This is not an exotic construct: it is exactly what Chrome/Edge DevTools emit from Copy as cURL (bash) (e.g. --data-raw $'...'), so any consumer that uses shell-quote to parse real-world copied shell commands silently gets the wrong arguments.
Current behaviour
The scanner treats the leading $ as the start of a parameter expansion (empty name → emits a literal $), and then treats the rest of the token as a plain single-quoted string. Consequences:
- the leading $ of the $' prefix is kept in the output (it should be dropped);
- ANSI-C escape sequences are not decoded (\n, \t, \x41, \', …);
- \' does not escape the quote — it terminates the string and the remainder is mis-parsed.
Reproduction
const { parse } = require('shell-quote'); // v1.10.0
const cases = [
'$' + "'" + '{"a":"${field}"}' + "'",
'$' + "'" + 'line1\\nline2' + "'",
'$' + "'" + 'a\\\'b' + "'",
'$' + "'" + 'tab\\there' + "'",
'$' + "'" + '\\x41' + "'",
'$' + "'" + 'cost is $5' + "'"
];
cases.forEach((c) => console.log(JSON.stringify(c), '->', JSON.stringify(parse(c)[0])));
| input |
bash output (printf '%s' <input>) |
shell-quote@1.10.0 |
| $'{"a":"${field}"}' |
{"a":"${field}"} |
${"a":"${field}"} ❌ leading $ kept |
| $'line1\nline2' |
line1 ⏎ line2 |
$line1\nline2 ❌ leading $ + escape not decoded |
| $'a\'b' |
a'b |
$a\b ❌ (quote terminated by \', \ kept) |
| $'tab\there' |
tab⇥here |
$tab\there ❌ |
| $'\x41' |
A |
$\x41 ❌ |
| $'cost is $5' |
cost is $5 |
$cost is $5 ❌ leading $ kept |
Expected behaviour
Per the bash manual, inside $'...':
- the documented escape sequences are decoded (\n, \t, \', \", \\, \nnn, \xHH, \uHHHH, \UHHHHHHHH, \cx, \a, \b, \e, \E, \f, \r, \v, \?, …);
- no parameter expansion, command substitution or brace expansion happens — ${field} and $5 stay literal;
- the $' prefix and the surrounding quotes are removed, and the token is not word-split.
Real-world impact / related
Thanks for maintaining this library!
Reactions are currently unavailable
Summary
shell-quote (reproduced on v1.10.0) does not implement bash's ANSI-C quoting — the $'...' form. This is not an exotic construct: it is exactly what Chrome/Edge DevTools emit from Copy as cURL (bash) (e.g. --data-raw $'...'), so any consumer that uses shell-quote to parse real-world copied shell commands silently gets the wrong arguments.
Current behaviour
The scanner treats the leading $ as the start of a parameter expansion (empty name → emits a literal $), and then treats the rest of the token as a plain single-quoted string. Consequences:
Reproduction
Expected behaviour
Per the bash manual, inside $'...':
Real-world impact / related
Thanks for maintaining this library!