Skip to content

Commit

Permalink
JS: fix unicode string escape when not a valid UTF-8 character
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed May 16, 2023
1 parent 9fbf910 commit 03bc264
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions js/js_test.go
Expand Up @@ -766,6 +766,7 @@ func TestJS(t *testing.T) {
{`var D;var{U,W,W}=y`, `var{U,W,W}=y,D`},
{`var A;var b=(function(){var e;})=c,d`, `var d,A,b=function(){var e}=c`},
{`0xB_BBBbAbA`, `3149642426`},
{`"\udFEb"`, `"\udFEb"`},

// bugs
{"var a=/\\s?auto?\\s?/i\nvar b;a,b", "var b,a=/\\s?auto?\\s?/i;a,b"}, // #14
Expand Down
4 changes: 4 additions & 0 deletions js/util.go
Expand Up @@ -1044,6 +1044,10 @@ func replaceEscapes(b []byte, quote byte, prefix, suffix int) []byte {
n += 2
}
m := utf8.RuneLen(rune(num))
if m == -1 {
i++
continue
}
utf8.EncodeRune(b[i+n-m:], rune(num))
n -= m
} else if c == '0' && (i+2 == len(b)-1 || b[i+2] < '0' || '7' < b[i+2]) {
Expand Down

0 comments on commit 03bc264

Please sign in to comment.