Description
run-script uses JSON.stringify to quote/escape command arguments:
run-script/lib/run-script-pkg.js
Line 30 in 477a99c
However, shells don't use the same quoting rule as JSON, which leads to incorrect behavior. In particular, literal newline characters (NL) get converted to \n (BACKSLASH N) by JSON.stringify, but bash does not treat \n as an escape sequence, and as a result the script receives \n (BACKSLASH N) as its argument.
To fix this problem, shell escaping should be used instead of JSON stringify.
I ran into this calling a script that invokes webpack with a --define argument containing a literal newline (NL) character. npm 7 converts this to a \n, which results in webpack substituting invalid javascript code leading to a parse error.