wilsonzlin / minify-js

Extremely fast JavaScript minifier, available for Rust and Node.js
Apache License 2.0
125 stars 5 forks source link

Minification breaks backslashes in double-quoted strings #20

Open penn5 opened 10 months ago

penn5 commented 10 months ago

The code alert("hello \"john\"");, when minified, becomes alert(`hello \\"john\\"`).

This is incorrect and results in two extra backslashes being introduced in the alert.

Tested in v0.5.6 because v0.6.0 has no prebuilt release (dead link in readme)

simonhollingshead commented 8 months ago

This is also true when trying to insert characters by their code.

RS="\x1e"; becomes RS=`\\x1e`; which then treats it as a literal string and no longer as a character code. I've had to use RS=String.fromCharCode(30); to stop it doing that.

rajch commented 4 months ago

This is a problem with single-quoted strings as well. input.split('\n') becomes input.split(`\\n`), which is wrong. In this case, I was able to use a regExp instead, like this: input.split(/\n/g), which works.