From 931862e97f2b8bc06d2de9b8e7e7e8e04500d063 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Tue, 21 Jan 2014 11:44:00 +0200 Subject: [PATCH] More chars that cannot be unescaped in regexps. --- lib/output.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/output.js b/lib/output.js index fce2c1ad..c2f49e9e 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1118,6 +1118,34 @@ function OutputStream(options) { DEFPRINT(AST_Number, function(self, output){ output.print(make_num(self.getValue())); }); + + function regexp_safe_literal(code) { + return [ + 0x5c , // \ + 0x2f , // / + 0x2e , // . + 0x2b , // + + 0x2a , // * + 0x3f , // ? + 0x28 , // ( + 0x29 , // ) + 0x5b , // [ + 0x5d , // ] + 0x7b , // { + 0x7d , // } + 0x24 , // $ + 0x5e , // ^ + 0x3a , // : + 0x7c , // | + 0x21 , // ! + 0x0a , // \n + 0x0d , // \r + 0xfeff , // Unicode BOM + 0x2028 , // unicode "line separator" + 0x2029 , // unicode "paragraph separator" + ].indexOf(code) < 0; + }; + DEFPRINT(AST_RegExp, function(self, output){ var str = self.getValue().toString(); if (output.option("ascii_only")) { @@ -1126,7 +1154,7 @@ function OutputStream(options) { str = str.split("\\\\").map(function(str){ return str.replace(/\\u[0-9a-fA-F]{4}|\\x[0-9a-fA-F]{2}/g, function(s){ var code = parseInt(s.substr(2), 16); - return code == 0xfeff || code == 0x2f || code == 10 || code == 13 || code == 0x2028 || code == 0x2029 ? s : String.fromCharCode(code); + return regexp_safe_literal(code) ? String.fromCharCode(code) : s; }); }).join("\\\\"); } -- 2.34.1