aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/bg/js/json-schema.js3
-rw-r--r--test/test-schema.js54
2 files changed, 56 insertions, 1 deletions
diff --git a/ext/bg/js/json-schema.js b/ext/bg/js/json-schema.js
index adb71fa3..ea1531ab 100644
--- a/ext/bg/js/json-schema.js
+++ b/ext/bg/js/json-schema.js
@@ -637,7 +637,8 @@ class JsonSchemaValidator {
if (propertySchema === null) { continue; }
info.valuePush(property, value);
info.schemaPush(property, propertySchema);
- value[property] = this._getValidValueOrDefault(propertySchema, value[property], info);
+ const hasValue = Object.prototype.hasOwnProperty.call(value, property);
+ value[property] = this._getValidValueOrDefault(propertySchema, hasValue ? value[property] : void 0, info);
info.schemaPop();
info.valuePop();
}
diff --git a/test/test-schema.js b/test/test-schema.js
index a79650d6..20f72518 100644
--- a/test/test-schema.js
+++ b/test/test-schema.js
@@ -540,6 +540,60 @@ function testGetValidValueOrDefault1() {
{test: 'value', test2: 2, test3: 10}
]
]
+ },
+
+ // Test value defaulting where hasOwnProperty is false
+ {
+ schema: {
+ type: 'object',
+ required: ['test'],
+ properties: {
+ test: {
+ type: 'string',
+ default: 'default'
+ }
+ }
+ },
+ inputs: [
+ [
+ {},
+ {test: 'default'}
+ ],
+ [
+ {test: 'value'},
+ {test: 'value'}
+ ],
+ [
+ Object.create({test: 'value'}),
+ {test: 'default'}
+ ]
+ ]
+ },
+ {
+ schema: {
+ type: 'object',
+ required: ['toString'],
+ properties: {
+ toString: {
+ type: 'string',
+ default: 'default'
+ }
+ }
+ },
+ inputs: [
+ [
+ {},
+ {toString: 'default'}
+ ],
+ [
+ {toString: 'value'},
+ {toString: 'value'}
+ ],
+ [
+ Object.create({toString: 'value'}),
+ {toString: 'default'}
+ ]
+ ]
}
];