diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-24 05:16:33 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-24 05:16:33 +0000 |
commit | 0faa0aa739c7d05c2b8b9a0274e9a1b11cd161a0 (patch) | |
tree | 462f0055b42e613db34842c1d571c9a446a63c1a | |
parent | 53d4e7dae39ef543467e4b6a04c3fc30814f29b4 (diff) | |
download | chromium_src-0faa0aa739c7d05c2b8b9a0274e9a1b11cd161a0.zip chromium_src-0faa0aa739c7d05c2b8b9a0274e9a1b11cd161a0.tar.gz chromium_src-0faa0aa739c7d05c2b8b9a0274e9a1b11cd161a0.tar.bz2 |
Ignore extra properties on schemas or instances that comes
from prototypes.
Review URL: http://codereview.chromium.org/215057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27044 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/resources/json_schema.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/chrome/renderer/resources/json_schema.js b/chrome/renderer/resources/json_schema.js index dcdfec8..750f89d 100644 --- a/chrome/renderer/resources/json_schema.js +++ b/chrome/renderer/resources/json_schema.js @@ -252,6 +252,15 @@ chromeHidden.JSONSchemaValidator.prototype.validateEnum = function( chromeHidden.JSONSchemaValidator.prototype.validateObject = function( instance, schema, path) { for (var prop in schema.properties) { + // It is common in JavaScript to add properties to Object.prototype. This + // check prevents such additions from being interpreted as required schema + // properties. + // TODO(aa): If it ever turns out that we actually want this to work, there + // are other checks we could put here, like requiring that schema properties + // be objects that have a 'type' property. + if (!schema.properties.hasOwnProperty(prop)) + continue; + var propPath = path ? path + "." + prop : prop; if (schema.properties[prop] == undefined) { this.addError(propPath, "invalidPropertyType"); @@ -270,6 +279,10 @@ chromeHidden.JSONSchemaValidator.prototype.validateObject = function( if (prop in schema.properties) continue; + // Any properties inherited through the prototype are ignored. + if (!instance.hasOwnProperty(prop)) + continue; + var propPath = path ? path + "." + prop : prop; if (schema.additionalProperties) this.validate(instance[prop], schema.additionalProperties, propPath); |