More chars that cannot be unescaped in regexps.
authorMihai Bazon <mihai@bazon.net>
Tue, 21 Jan 2014 09:44:00 +0000 (11:44 +0200)
committerMihai Bazon <mihai@bazon.net>
Tue, 21 Jan 2014 09:44:00 +0000 (11:44 +0200)
lib/output.js

index fce2c1a..c2f49e9 100644 (file)
@@ -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("\\\\");
         }