diff options
author | skerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 15:21:43 +0000 |
---|---|---|
committer | skerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 15:21:43 +0000 |
commit | 90f8e2168bc12e74f37dc82ea78a2309c6cb53cc (patch) | |
tree | 257b178d548333ed6a2406b3931f0baf5a2fe0f5 /chrome/renderer | |
parent | c369ffd33760e7b2f6aad22b3747dff321bf497a (diff) | |
download | chromium_src-90f8e2168bc12e74f37dc82ea78a2309c6cb53cc.zip chromium_src-90f8e2168bc12e74f37dc82ea78a2309c6cb53cc.tar.gz chromium_src-90f8e2168bc12e74f37dc82ea78a2309c6cb53cc.tar.bz2 |
Forbid NaN and infinite numbers in extensions API type validator.
BUG=51449
TEST=JsonSchemaTest.TestNumber
Review URL: http://codereview.chromium.org/3158015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56350 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/resources/json_schema.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/chrome/renderer/resources/json_schema.js b/chrome/renderer/resources/json_schema.js index fee7b02..ff1c0a0 100644 --- a/chrome/renderer/resources/json_schema.js +++ b/chrome/renderer/resources/json_schema.js @@ -72,6 +72,7 @@ chromeHidden.JSONSchemaValidator.messages = { stringMinLength: "String must be at least * characters long.", stringMaxLength: "String must not be more than * characters long.", stringPattern: "String must match the pattern: *.", + numberFiniteNotNan: "Value must not be *.", numberMinValue: "Value must not be less than *.", numberMaxValue: "Value must not be greater than *.", numberMaxDecimal: "Value must not have more than * decimal places.", @@ -395,6 +396,15 @@ chromeHidden.JSONSchemaValidator.prototype.validateString = function( */ chromeHidden.JSONSchemaValidator.prototype.validateNumber = function( instance, schema, path) { + + // Forbid NaN, +Infinity, and -Infinity. Our APIs don't use them, and + // JSON serialization encodes them as 'null'. Re-evaluate supporting + // them if we add an API that could reasonably take them as a parameter. + if (isNaN(instance) || + instance == Number.POSITIVE_INFINITY || + instance == Number.NEGATIVE_INFINITY ) + this.addError(path, "numberFiniteNotNan", [instance]); + if (schema.minimum && instance < schema.minimum) this.addError(path, "numberMinValue", [schema.minimum]); |