From a219601931a3e9e3819628a4f3d059a8f2d76547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20N=C4=9Bmec?= Date: Mon, 6 Dec 2010 03:54:22 +0100 Subject: [PATCH] Provide util.regexpSource to avoid escaping slash when not necessary. --- common/content/autocommands.js | 4 ++-- common/content/options.js | 2 +- common/modules/util.jsm | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/common/content/autocommands.js b/common/content/autocommands.js index 6dfba95e..3c1a0ad6 100644 --- a/common/content/autocommands.js +++ b/common/content/autocommands.js @@ -86,7 +86,7 @@ const AutoCommands = Module("autocommands", { + template.map(items, function (item) -  {item.pattern.source} +  {util.regexpSource(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 " + autoCmd.pattern.source.quote(), 8); + dactyl.echomsg("Executing " + event + " Auto commands for " + util.regexpSource(autoCmd.pattern).quote(), 8); lastPattern = autoCmd.pattern; dactyl.echomsg("autocommand " + autoCmd.command, 9); diff --git a/common/content/options.js b/common/content/options.js index d682c787..48a5ab23 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(re.source.replace(/\\(.)/g, function (m, n1) n1 == "/" ? n1 : m), /^!|:/) + + unparseRegexp: function (re) re.bang + Option.quote(util.regexpSource(re), /^!|:/) + (typeof re.result === "boolean" ? "" : ":" + Option.quote(re.result)), getKey: { diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 7f427d21..e0b58b5f 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -836,6 +836,14 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) return RegExp(expr, flags); }, + /** + * 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), + maxErrors: 15, errors: Class.memoize(function () []), reportError: function (error) {