trullock / NUglify

NUglify is a HTML, JavaScript and CSS minification Library for .NET (fork of AjaxMin + new features)
Other
396 stars 79 forks source link

Template literals do not preserve escaping of dollar sign #291

Closed jdom closed 2 years ago

jdom commented 2 years ago

Looks like the template strings have issues when escaping the dollar sign (EDIT: Code updated because escaping of backslash and backtick was already fixed in the latest version). Single and double characters work well:

Input:

const tickEscaping = `\\ \` \$`;              // doesn't work, it removes backslash from dollar sign
const doubleQuoteEscaping = "\\ \" ' \$";     // minifies OK as dollar sign isn't an escape character in this context (I think)
const singleQuoteEscaping = '\\ \' " \$';     // minifies OK as dollar sign isn't an escape character in this context (I think)

Becomes (line endings added for readability):

const tickEscaping=`\\ \` $`,
doubleQuoteEscaping="\\ \" ' $",
singleQuoteEscaping="\\ ' \" $"

Expected (without line-endings actually):

const tickEscaping=`\\ \` \$`,
doubleQuoteEscaping="\\ \" ' $",
singleQuoteEscaping="\\ ' \" $"
trullock commented 2 years ago

Are you on latest? Just fixed this...

jdom commented 2 years ago

Oh, sweet, just tried it and it works... I did have the latest, but at some point I went back to the version I had in my project, and after I went back to latest, looks like I didn't re-build the console app (which is where I'm testing the small repros).

Thanks a lot, closing.

jdom commented 2 years ago

Wait, the escaping of the $ character isn't working... I just saw the commit, and see that your fix is targetted to the escaping of backslash and backtick

jdom commented 2 years ago

submitting a PR with the fix

jdom commented 2 years ago

Updated the input and actual result from the bug description, to account for the already fixed escaping of backslash and backtick