diff --git a/js/src/javascript/tokenizer.js b/js/src/javascript/tokenizer.js index 2b2b73fb0..197e9a47a 100644 --- a/js/src/javascript/tokenizer.js +++ b/js/src/javascript/tokenizer.js @@ -516,6 +516,9 @@ function unescape_string(s) { } else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) { // single-quote, apostrophe, backslash - escape these out += '\\' + String.fromCharCode(escaped); + } else if (escaped === 0x2028 || escaped === 0x2029 || escaped === 0xfeff) { + // U+2028 LINE SEPARATOR, U+2029 PARAGRAPH SEPARATOR, U+FEFF BOM are JavaScript line terminators, keep escaped so the output remains valid JS. + out += '\\' + matched[0]; } else { out += String.fromCharCode(escaped); } diff --git a/python/jsbeautifier/javascript/tokenizer.py b/python/jsbeautifier/javascript/tokenizer.py index f86f9ae82..30972695c 100644 --- a/python/jsbeautifier/javascript/tokenizer.py +++ b/python/jsbeautifier/javascript/tokenizer.py @@ -628,6 +628,9 @@ def unescape_string(self, s): elif escaped == 0x22 or escaped == 0x27 or escaped == 0x5C: # single-quote, apostrophe, backslash - escape these out += "\\" + chr(escaped) + elif escaped in (0x2028, 0x2029, 0xFEFF): + # U+2028 LINE SEPARATOR, U+2029 PARAGRAPH SEPARATOR, U+FEFF BOM are JavaScript line terminators, keep escaped so the output remains valid JS. + out += "\\" + matched.group(0) else: out += self.acorn.six.unichr(escaped)