From 252e1965c02aa2c2bec036739116f29b789afa76 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Fri, 25 Sep 2009 19:36:10 +1000 Subject: [PATCH] Fix numeric option value validation for "". Number("") => 0, Number("077") => 77, parseInt("008") => 0 etc. --HG-- extra : transplant_source : %5B%A2%EC%06%BB%85A%C7%D3%B5%7E%B5%91f%9B1%8F%D3%3D%98 --- common/content/options.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/content/options.js b/common/content/options.js index e96b6b5b..8eeb6ea8 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -340,10 +340,11 @@ Option.prototype = { break; case "number": - let value = Number(values); // deduce radix + // TODO: support floats? Validators need updating. + if (!/^[+-]?(?:0x[0-9a-f]+|0[0-7]+|0|[1-9]\d*)$/i.test(values)) + return "E521: Number required after := " + this.name + "=" + values; - if (isNaN(value) || value != parseInt(value)) - return "E521: Number required"; + let value = parseInt(values/* deduce radix */); switch (operator) { @@ -411,7 +412,7 @@ Option.prototype = { break; default: - return "E685: Internal error: option type `" + option.type + "' not supported"; + return "E685: Internal error: option type `" + this.type + "' not supported"; } if (newValue == null)