summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 22:20:30 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 22:20:30 +0000
commitd41661b5e24c8d774acea07c05ef2e5896587e56 (patch)
treef8bd3d8888f6a05efc15215915d755d86f549f3c /chrome
parentcd8fa42ec2477735076c9e90c11f7a7ea7d19b9b (diff)
downloadchromium_src-d41661b5e24c8d774acea07c05ef2e5896587e56.zip
chromium_src-d41661b5e24c8d774acea07c05ef2e5896587e56.tar.gz
chromium_src-d41661b5e24c8d774acea07c05ef2e5896587e56.tar.bz2
Reland: No longer accept 'null' as signifying unset optional object property in extension calls
This changes the json schema validation to treat a object property set to null as significant, rather than meaning the property is not specified. original review: http://codereview.chromium.org/1558021/show BUG=39465 TBR=oshima TEST=all tests should pass Review URL: http://codereview.chromium.org/1618005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43767 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/renderer/resources/json_schema.js5
-rw-r--r--chrome/test/data/extensions/json_schema_test.js23
2 files changed, 14 insertions, 14 deletions
diff --git a/chrome/renderer/resources/json_schema.js b/chrome/renderer/resources/json_schema.js
index 6d0ef53..fee7b02 100644
--- a/chrome/renderer/resources/json_schema.js
+++ b/chrome/renderer/resources/json_schema.js
@@ -164,7 +164,7 @@ chromeHidden.JSONSchemaValidator.prototype.validate = function(
// that schema too.
if (schema.extends)
this.validate(instance, schema.extends, path);
-
+
// If the schema has a $ref property, the instance must validate against
// that schema too. It must be present in this.types to be referenced.
if (schema["$ref"]) {
@@ -267,8 +267,7 @@ chromeHidden.JSONSchemaValidator.prototype.validateObject = function(
var propPath = path ? path + "." + prop : prop;
if (schema.properties[prop] == undefined) {
this.addError(propPath, "invalidPropertyType");
- } else if (prop in instance && instance[prop] !== null &&
- instance[prop] !== undefined) {
+ } else if (prop in instance && instance[prop] !== undefined) {
this.validate(instance[prop], schema.properties[prop], propPath);
} else if (!schema.properties[prop].optional) {
this.addError(propPath, "propertyRequired");
diff --git a/chrome/test/data/extensions/json_schema_test.js b/chrome/test/data/extensions/json_schema_test.js
index 3f55c08..58fa8f3 100644
--- a/chrome/test/data/extensions/json_schema_test.js
+++ b/chrome/test/data/extensions/json_schema_test.js
@@ -189,8 +189,8 @@ function testObject() {
}
};
- assertValid("Object", {foo:"foo",bar:42}, schema);
- assertNotValid("Object", {foo:"foo",bar:42,"extra":true}, schema,
+ assertValid("Object", {foo:"foo", bar:42}, schema);
+ assertNotValid("Object", {foo:"foo", bar:42,"extra":true}, schema,
[formatError("unexpectedProperty")]);
assertNotValid("Object", {foo:"foo"}, schema,
[formatError("propertyRequired")]);
@@ -198,19 +198,20 @@ function testObject() {
[formatError("invalidType", ["integer", "string"])]);
schema.additionalProperties = { type: "any" };
- assertValid("Object", {foo:"foo",bar:42,"extra":true}, schema);
- assertValid("Object", {foo:"foo",bar:42,"extra":"foo"}, schema);
+ assertValid("Object", {foo:"foo", bar:42, "extra":true}, schema);
+ assertValid("Object", {foo:"foo", bar:42, "extra":"foo"}, schema);
schema.additionalProperties = { type: "boolean" };
- assertValid("Object", {foo:"foo",bar:42,"extra":true}, schema);
- assertNotValid("Object", {foo:"foo",bar:42,"extra":"foo"}, schema,
+ assertValid("Object", {foo:"foo", bar:42, "extra":true}, schema);
+ assertNotValid("Object", {foo:"foo", bar:42, "extra":"foo"}, schema,
[formatError("invalidType", ["boolean", "string"])]);
schema.properties.bar.optional = true;
- assertValid("Object", {foo:"foo",bar:42}, schema);
+ assertValid("Object", {foo:"foo", bar:42}, schema);
assertValid("Object", {foo:"foo"}, schema);
- assertValid("Object", {foo:"foo",bar:null}, schema);
- assertValid("Object", {foo:"foo",bar:undefined}, schema);
+ assertNotValid("Object", {foo:"foo", bar:null}, schema,
+ [formatError("invalidType", ["integer", "null"])]);
+ assertValid("Object", {foo:"foo", bar:undefined}, schema);
assertNotValid("Object", {foo:"foo", bar:"42"}, schema,
[formatError("invalidType", ["integer", "string"])]);
@@ -234,7 +235,7 @@ function testObject() {
assertValid("Object", b, classBSchema);
assertValid("Object", b, classASchema);
assertNotValid("Object", c, classASchema,
- [formatError("notInstance", [classASchema.isInstanceOf])]);
+ [formatError("notInstance", [classASchema.isInstanceOf])]);
}
function testTypeReference() {
@@ -288,7 +289,7 @@ function testTypeReference() {
// Valida type references internally defined.
assertValid("", {foo:"foo",bar:-4,baz:-2}, schemaInlineReference);
-
+
// Failures in validation, but succesful schema reference.
assertNotValid("", {foo:"foo",bar:4,baz:"a"}, schema,
[formatError("stringMinLength", [2])], referencedTypes);