summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/js/data/json-schema.js12
-rw-r--r--test/test-json-schema.js2
2 files changed, 9 insertions, 5 deletions
diff --git a/ext/js/data/json-schema.js b/ext/js/data/json-schema.js
index 8fb920fc..b91bfb47 100644
--- a/ext/js/data/json-schema.js
+++ b/ext/js/data/json-schema.js
@@ -874,9 +874,13 @@ class JsonSchemaProxyHandler {
let propertySchema;
if (Array.isArray(target)) {
- property = this._getArrayIndex(property);
- if (property === null) { throw new Error(`Property ${property} cannot be assigned to array`); }
- if (property > target.length) { throw new Error('Array index out of range'); }
+ const index = this._getArrayIndex(property);
+ if (index === null) {
+ target[property] = value;
+ return true;
+ }
+ if (index > target.length) { throw new Error('Array index out of range'); }
+ property = index;
propertySchema = this._schema.getArrayItemSchema(property);
} else {
propertySchema = this._schema.getObjectPropertySchema(property);
@@ -894,7 +898,7 @@ class JsonSchemaProxyHandler {
deleteProperty(target, property) {
const required = (
(typeof target === 'object' && target !== null) ?
- (Array.isArray(target) || this._schema.isObjectPropertyRequired(property)) :
+ (!Array.isArray(target) && this._schema.isObjectPropertyRequired(property)) :
true
);
if (required) {
diff --git a/test/test-json-schema.js b/test/test-json-schema.js
index 1c61f1b8..cc92c851 100644
--- a/test/test-json-schema.js
+++ b/test/test-json-schema.js
@@ -945,7 +945,7 @@ function testProxy1() {
tests: [
{error: false, value: ['default'], action: (value) => { value[0] = 'string'; }},
{error: true, value: ['default'], action: (value) => { value[0] = null; }},
- {error: true, value: ['default'], action: (value) => { delete value[0]; }},
+ {error: false, value: ['default'], action: (value) => { delete value[0]; }},
{error: false, value: ['default'], action: (value) => { value[1] = 'string'; }},
{error: false, value: ['default'], action: (value) => {
value[1] = 'string';