Skip to content

Commit

Permalink
JS: fix minifying strings where the last character needs to be escape…
Browse files Browse the repository at this point in the history
…d as we change the quotes
  • Loading branch information
tdewolff committed Mar 12, 2024
1 parent 664dc9a commit 11e0f35
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func TestJS(t *testing.T) {
{`"a"+"b"+5+"c"+"d"`, `"ab"+5+"cd"`},
{`"a"+"b"+5+6+"d"`, `"ab"+5+6+"d"`},
{"`$${foo}`", "`$${foo}`"},
{"'\\n\\nCheck the render method of `'", "`\n\nCheck the render method of \\``"},

// rename true, false, undefined, Infinity
{`x=true`, `x=!0`},
Expand Down
2 changes: 1 addition & 1 deletion js/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ func replaceEscapes(b []byte, quote byte, prefix, suffix int) []byte {
// strip unnecessary escapes
j := 0
start := 0
for i := prefix; i < len(b)-suffix-1; i++ {
for i := prefix; i < len(b)-suffix; i++ {
if c := b[i]; c == '\\' {
c = b[i+1]
if c == quote || c == '\\' || quote != '`' && (c == 'n' || c == 'r') || c == '0' && (len(b)-suffix <= i+2 || b[i+2] < '0' || '7' < b[i+2]) {
Expand Down

0 comments on commit 11e0f35

Please sign in to comment.