From 5606b9695704c87406feba251e35cef71c8529b1 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 15 Feb 2011 13:06:40 -0500 Subject: [PATCH] Require "x" flag in util.regexp for "extended" regex processing. --- common/components/protocols.js | 2 +- common/content/abbreviations.js | 4 +-- common/content/dactyl.js | 47 ++++++++++++++++----------------- common/modules/commands.jsm | 6 ++--- common/modules/highlight.jsm | 4 +-- common/modules/io.jsm | 2 +- common/modules/styles.jsm | 10 +++---- common/modules/template.jsm | 2 +- common/modules/util.jsm | 16 ++++++++--- 9 files changed, 51 insertions(+), 42 deletions(-) diff --git a/common/components/protocols.js b/common/components/protocols.js index e925da69..ac8f0920 100644 --- a/common/components/protocols.js +++ b/common/components/protocols.js @@ -257,7 +257,7 @@ function XMLChannel(uri, contentType) { ([^]*) )? $ - ]]>).exec(stream.read(4096)); + ]]>, "x").exec(stream.read(4096)); this.writes.push(pre); if (doctype) { this.writes.push(doctype + "[\n"); diff --git a/common/content/abbreviations.js b/common/content/abbreviations.js index 462b93ea..0e9a7cb5 100644 --- a/common/content/abbreviations.js +++ b/common/content/abbreviations.js @@ -157,14 +157,14 @@ var Abbreviations = Module("abbreviations", { (^ | \s | ) (+ )$ | // full-id (^ | \s | ) (+ )$ | // end-id (^ | \s ) (\S* )$ // non-id - ]]>, "", params); + ]]>, "x", params); this._check = util.regexp(<>+ | // full-id + | // end-id \S* // non-id ) $ - ]]>, "", params); + ]]>, "x", params); }, get: deprecated("group.abbrevs.get", { get: function get() this.user.closure.get }), diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 23403eee..933de1b9 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -696,9 +696,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { ) | (?: ^ [^\S\n]* \n) + - ]]>, "gmy"); + ]]>, "gmxy"); - let betas = util.regexp(/\[(b\d)\]/, "g"); + let betas = util.regexp(/\[(b\d)\]/, "gx"); let beta = array(betas.iterate(NEWS)) .map(function (m) m[1]).uniq().slice(-1)[0]; @@ -1240,26 +1240,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { else urls = [str]; - let re = util.regexp(+ (:\d+)? (/ .*) | - + (:\d+) | - + \. [a-z0-9]+ | - localhost - ) $ - ]]>, "i", { - domain: util.regexp(String.replace(, /U/g, "\\u")) - }); - return urls.map(function (url) { url = url.trim(); @@ -1284,15 +1264,34 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { return searchURL; // If it looks like URL-ish (foo.com/bar), let Gecko figure it out. - if (re.test(url)) + if (this.urlish.test(url)) return util.createURI(url).spec; // Pass it off to the default search engine or, failing // that, let Gecko deal with it as is. return bookmarks.getSearchURL(url, true) || util.createURI(url).spec; - }); + }, this); }, stringToURLArray: deprecated("dactyl.parseURLs", "parseURLs"), + urlish: Class.memoize(function () util.regexp(+ (:\d+)? (/ .*) | + + (:\d+) | + + \. [a-z0-9]+ | + localhost + ) $ + ]]>, "ix", { + domain: util.regexp(String.replace(, /U/g, "\\u"), "x") + })), pluginFiles: {}, diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index 4828e978..39ed4c0f 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -1095,7 +1095,7 @@ var Commands = Module("commands", { ] [^ ]* - ]]>, "g", { + ]]>, "gx", { forbid: util.regexp(String.replace(, /U/g, "\\u")) + ]]>, /U/g, "\\u"), "x") }), validName: Class.memoize(function () util.regexp("^" + this.nameRegexp.source + "$")), @@ -1137,7 +1137,7 @@ var Commands = Module("commands", { (?:. | \n)*? )? $ - ]]>, "", { + ]]>, "x", { name: this.nameRegexp })), diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index 1c53104f..782b9ca5 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -224,7 +224,7 @@ var Highlights = Module("Highlight", { \{ ([^}]*) \} \s* $ - ]]>, "gm"), + ]]>, "gmx"), sheetRegexp: util.regexp( (?:[^;\s]|\s[^;\s])+ )? )? \s* (?P .*) $ - ]]>), + ]]>, "x"), /** * Bulk loads new CSS rules, in the format of, diff --git a/common/modules/io.jsm b/common/modules/io.jsm index 585b8e63..71c72ba2 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -966,7 +966,7 @@ unlet s:cpo_save ) (?P \/[^\/]* )? $ - ]]>).exec(context.filter); + ]]>, "x").exec(context.filter); if (match) { if (!match.path) { context.key = match.proto; diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index d9da6c68..b83f99dc 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -473,7 +473,7 @@ var Styles = Module("Styles", { )? ) (?P * (?: ; | $) ) - ]]>, "gi", + ]]>, "gix", { space: /(?: \s | \/\* .*? \*\/ )/, string: /(?:" (?:[^\\"]|\\.)* (?:"|$) | '(?:[^\\']|\\.)* (?:'|$) )/ @@ -491,7 +491,7 @@ var Styles = Module("Styles", { )? ) (?P * (?: ; | $) ) - ]]>, "gi", this), + ]]>, "gix", this), get function() util.regexp( @@ -499,7 +499,7 @@ var Styles = Module("Styles", { (?: | [^)]* ) \s* (?: \) | $) ) - ]]>, "g", this), + ]]>, "gx", this), space: /(?: \s | \/\* .*? \*\/ )/, @@ -508,7 +508,7 @@ var Styles = Module("Styles", { " (?:[^\\"]|\\.)* (?:"|$) | ' (?:[^\\']|\\.)* (?:'|$) ) - ]]>, "g", this), + ]]>, "gx", this), get token() util.regexp( @@ -520,7 +520,7 @@ var Styles = Module("Styles", { | + | [^;}\s]+ ) - ]]>, "gi", this) + ]]>, "gix", this) }) }, { commands: function (dactyl, modules, window) { diff --git a/common/modules/template.jsm b/common/modules/template.jsm index be1e5ab7..42220bba 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -349,7 +349,7 @@ var Template = Module("Template", { (?P
 [/\s]|^)
             (?P '[\w-]+' | :(?:[\w-]+|!) | (?:._)?<[\w-]+> )
             (?=      [[\)!,;./\s]|$)
-        ]]>, "g");
+        ]]>, "gx");
         return this.highlightSubstrings(str, (function () {
             for (let res in re.iterate(str))
                 yield [res.index + res.pre.length, res.tag.length];
diff --git a/common/modules/util.jsm b/common/modules/util.jsm
index ed47972a..e8b02d41 100644
--- a/common/modules/util.jsm
+++ b/common/modules/util.jsm
@@ -349,7 +349,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
                 (< ((?:[a-z]-)?[a-z-]+?) >) | // 3 4
                 (\}>) // 5
             )
-        ]]>, "giy");
+        ]]>, "gixy");
         macro = String(macro);
         let end = 0;
         for (let match in re.iterate(macro)) {
@@ -1323,14 +1323,21 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
      * @returns {RegExp} A custom regexp object.
      */
     regexp: update(function (expr, flags, tokens) {
+        flags = flags || [k for ([k, v] in Iterator({ g: "global", i: "ignorecase", m: "multiline", y: "sticky" }))
+                          if (expr[v])].join("");
+
         if (isinstance(expr, ["RegExp"]))
             expr = expr.source;
 
+        // Replace replacement .
         if (tokens)
             expr = String.replace(expr, /(\(?P)?<(\w+)>/g, function (m, n1, n2) !n1 && set.has(tokens, n2) ? tokens[n2].dactylSource || tokens[n2].source || tokens[n2] : m);
 
-        expr = String.replace(expr, /(\\.)|\/\/[^\n]*|\/\*[^]*?\*\/|\s+/gm, function (m, m1) m1 || "");
+        // Strip comments and white space.
+        if (/x/.test(flags))
+            expr = String.replace(expr, /(\\.)|\/\/[^\n]*|\/\*[^]*?\*\/|\s+/gm, function (m, m1) m1 || "");
 
+        // Replace (?P parameters)
         if (/\(\?P