diff --git a/common/content/commands.js b/common/content/commands.js index 06995c8e..e1b45cbc 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -995,6 +995,58 @@ const Commands = Module("commands", { } }, + nameRegexp: util.regexp( + ] + [^ ]* + ]]>, "", { + forbid: util.regexp() + }), + + validName: Class.memoize(function () RegExp("^" + this.nameRegexp.source + "$")), + + _commandRegexp: Class.memoize(function () util.regexp( | !) + (!)? + (\s*) + ) + ( + (?:. | \n)*? + )? + $ + ]]>, "", { + name: this.nameRegexp + })), + /** * Parses a complete Ex command. * @@ -1014,9 +1066,7 @@ const Commands = Module("commands", { // remove comments str.replace(/\s*".*$/, ""); - // 0 - count, 1 - cmd, 2 - special, 3 - args - let matches = str.match(/^([:\s]*(\d+|%)?([a-zA-Z]+|!)(!)?(\s*))((?:.|\n)*?)?$/); - //var matches = str.match(/^:*(\d+|%)?([a-zA-Z]+|!)(!)?(?:\s*(.*?)\s*)?$/); + let matches = this._commandRegexp.exec(str); if (!matches) return []; @@ -1240,7 +1290,7 @@ const Commands = Module("commands", { function (args) { let cmd = args[0]; - dactyl.assert(!/\W/.test(cmd || ''), "E182: Invalid command name"); + dactyl.assert(!cmd || commands.validName.test(cmd), "E182: Invalid command name"); if (args.literalArg) { let completeOpt = args["-complete"]; diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 2268bc8e..da855270 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -480,7 +480,7 @@ function isinstance(targ, src) { /** * Returns true if obj is a non-null object. */ -function isObject(obj) typeof obj === "object" && obj != null; +function isObject(obj) typeof obj === "object" && obj != null || obj instanceof Ci.nsISupports; /** * Returns true if and only if its sole argument is an diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 97921006..cc9b6448 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -773,11 +773,11 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) XML.prettyPrinting = false; XML.ignoreWhitespace = false; - if (object === null) - return "null\n"; + if (object == null) + return object + "\n"; - if (typeof object !== "object") - return false; + if (!isObject(object)) + return String(object); if (object instanceof Ci.nsIDOMElement) { const NAMESPACES = array.toObject([