diff options
| author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-05-26 21:08:24 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-26 21:08:24 -0400 | 
| commit | 52aa92208c74d919252cc48f3d6eae519035de9d (patch) | |
| tree | f97e6a40eb38bea16137b7729c39c788a4329a7a /ext/js | |
| parent | 8ed712512b43c3a546369bfdd247a7c1bb347c4f (diff) | |
Fix set/deleteProperty not allowing array splicing (#1713)
* Fix set/deleteProperty not allowing array splicing
* Update tests
Diffstat (limited to 'ext/js')
| -rw-r--r-- | ext/js/data/json-schema.js | 12 | 
1 files changed, 8 insertions, 4 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) { |