diff --git a/common/content/autocommands.js b/common/content/autocommands.js index 3c1a0ad6..fd3d876a 100644 --- a/common/content/autocommands.js +++ b/common/content/autocommands.js @@ -86,7 +86,7 @@ const AutoCommands = Module("autocommands", { + template.map(items, function (item) -  {util.regexpSource(item.pattern)} +  {util.regexp.getSource(item.pattern)} {item.command} )) } @@ -114,7 +114,7 @@ const AutoCommands = Module("autocommands", { for (let [, autoCmd] in Iterator(autoCmds)) { if (autoCmd.pattern.test(url) ^ !autoCmd.pattern.result) { if (!lastPattern || lastPattern.source != autoCmd.pattern.source) - dactyl.echomsg("Executing " + event + " Auto commands for " + util.regexpSource(autoCmd.pattern).quote(), 8); + dactyl.echomsg("Executing " + event + " Auto commands for " + util.regexp.getSource(autoCmd.pattern).quote(), 8); lastPattern = autoCmd.pattern; dactyl.echomsg("autocommand " + autoCmd.command, 9); diff --git a/common/content/completion.js b/common/content/completion.js index d5922404..7dce069b 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -921,7 +921,7 @@ const Completion = Module("completion", { function (tok) contains(item.url, tok) || contains(item.title, tok))); - let re = RegExp(tokens.filter(util.identity).map(util.escapeRegexp).join("|"), "g"); + let re = RegExp(tokens.filter(util.identity).map(util.regexp.escape).join("|"), "g"); function highlight(item, text, i) process[i].call(this, item, template.highlightRegexp(text, re)); let process = context.process; context.process = [ diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 0e4bb049..69ce4149 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -1274,7 +1274,7 @@ const Dactyl = Module("dactyl", { setter: function (value) { let win = document.documentElement; function updateTitle(old, current) { - document.title = document.title.replace(RegExp("(.*)" + util.escapeRegexp(old)), "$1" + current); + document.title = document.title.replace(RegExp("(.*)" + util.regexp.escape(old)), "$1" + current); } // TODO: remove this FF3.5 test when we no longer support 3.0 diff --git a/common/content/options.js b/common/content/options.js index f1dca9f4..54a97f11 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -391,7 +391,7 @@ const Option = Class("Option", { re.toString = function () Option.unparseRegexp(this); return re; }, - unparseRegexp: function (re) re.bang + Option.quote(util.regexpSource(re), /^!|:/) + + unparseRegexp: function (re) re.bang + Option.quote(util.regexp.getSource(re), /^!|:/) + (typeof re.result === "boolean" ? "" : ":" + Option.quote(re.result)), getKey: { diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index c7a764b3..730e3dde 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -493,7 +493,7 @@ const File = Class("File", { // expand ~ // Yuck. - if (!relative && RegExp("~(?:$|[/" + util.escapeRegexp(File.PATH_SEP) + "])").test(path)) { + if (!relative && RegExp("~(?:$|[/" + util.regexp.escape(File.PATH_SEP) + "])").test(path)) { // Try $HOME first, on all systems let home = getenv("HOME"); diff --git a/common/modules/util.jsm b/common/modules/util.jsm index d7b11554..e1f35952 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -387,16 +387,6 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) return str.replace(/&/g, "&").replace(//g, function (m, n1) set.has(tokens, n1) ? tokens[n1].source || tokens[n1] : m); expr = String.replace(expr, /\/\/[^\n]*|\/\*[^]*?\*\//gm, "") .replace(/\s+/g, ""); return RegExp(expr, flags); - }, + }, { + /** + * Escapes Regular Expression special characters in *str*. + * + * @param {string} str + * @returns {string} + */ + escape: function regexp_escape(str) str.replace(/([\\{}()[\].?*+])/g, "\\$1"), - /** - * Given a RegExp, returns its source in the form showable to the user. - * - * @param {RegExp} re The regexp showable source of which is to be returned. - * @returns {string} - */ - regexpSource: function regexpSource(re) re.source.replace(/\\(.)/g, function (m0, m1) m1 === "/" ? "/" : m0), + /** + * Given a RegExp, returns its source in the form showable to the user. + * + * @param {RegExp} re The regexp showable source of which is to be returned. + * @returns {string} + */ + getSource: function regexp_getSource(re) re.source.replace(/\\(.)/g, function (m0, m1) m1 === "/" ? "/" : m0), + }), maxErrors: 15, errors: Class.memoize(function () []),