Give a good error message if an invalid regular expression is found.
authorChris Cowan <agentme49@gmail.com>
Thu, 14 May 2015 19:03:54 +0000 (12:03 -0700)
committerRichard van Velzen <rvanvelzen@experty.com>
Wed, 29 Jul 2015 13:05:59 +0000 (15:05 +0200)
lib/parse.js

index e65c4fa..70ee2e8 100644 (file)
@@ -480,7 +480,13 @@ function tokenizer($TEXT, filename, html5_comments) {
             regexp += ch;
         }
         var mods = read_name();
-        return token("regexp", new RegExp(regexp, mods));
+        var r;
+        try {
+          r = new RegExp(regexp, mods);
+        } catch(e) {
+          parse_error("Invalid regular expression");
+        }
+        return token("regexp", r);
     });
 
     function read_operator(prefix) {