From 11e0f3581baf2591573c485d42f5caee5ecbc9f9 Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Mon, 11 Mar 2024 21:28:06 -0300 Subject: [PATCH] JS: fix minifying strings where the last character needs to be escaped as we change the quotes --- js/js_test.go | 1 + js/util.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/js/js_test.go b/js/js_test.go index 3db67c6bd3..547eff4394 100644 --- a/js/js_test.go +++ b/js/js_test.go @@ -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`}, diff --git a/js/util.go b/js/util.go index 97fb7ecf28..a674a71217 100644 --- a/js/util.go +++ b/js/util.go @@ -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]) {