Parse regexes properly
authorAnthony Van de Gejuchte <anthonyvdgent@yahoo.com>
Tue, 10 Feb 2015 15:57:17 +0000 (16:57 +0100)
committerRichard van Velzen <rvanvelzen1@gmail.com>
Wed, 11 Feb 2015 17:29:15 +0000 (18:29 +0100)
bin/uglifyjs

index c9f4c12..31133c9 100755 (executable)
@@ -178,8 +178,13 @@ if (BEAUTIFY)
     UglifyJS.merge(OUTPUT_OPTIONS, BEAUTIFY);
 
 if (ARGS.comments) {
-    if (/^\//.test(ARGS.comments)) {
-        OUTPUT_OPTIONS.comments = new Function("return(" + ARGS.comments + ")")();
+    if (/^\/.*\/[a-zA-Z]*$/.test(ARGS.comments)) {
+        var regex_pos = ARGS.comments.lastIndexOf("/");
+        try {
+            OUTPUT_OPTIONS.comments = new RegExp(ARGS.comments.substr(1, regex_pos - 1), ARGS.comments.substr(regex_pos + 1));
+        } catch (e) {
+            sys.error("ERROR: Invalid --comments: " + e.message);
+        }
     } else if (ARGS.comments == "all") {
         OUTPUT_OPTIONS.comments = true;
     } else {