Fix set/deleteProperty not allowing array splicing (#1713)
* Fix set/deleteProperty not allowing array splicing * Update tests
This commit is contained in:
parent
8ed712512b
commit
52aa92208c
@ -874,9 +874,13 @@ class JsonSchemaProxyHandler {
|
|||||||
|
|
||||||
let propertySchema;
|
let propertySchema;
|
||||||
if (Array.isArray(target)) {
|
if (Array.isArray(target)) {
|
||||||
property = this._getArrayIndex(property);
|
const index = this._getArrayIndex(property);
|
||||||
if (property === null) { throw new Error(`Property ${property} cannot be assigned to array`); }
|
if (index === null) {
|
||||||
if (property > target.length) { throw new Error('Array index out of range'); }
|
target[property] = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (index > target.length) { throw new Error('Array index out of range'); }
|
||||||
|
property = index;
|
||||||
propertySchema = this._schema.getArrayItemSchema(property);
|
propertySchema = this._schema.getArrayItemSchema(property);
|
||||||
} else {
|
} else {
|
||||||
propertySchema = this._schema.getObjectPropertySchema(property);
|
propertySchema = this._schema.getObjectPropertySchema(property);
|
||||||
@ -894,7 +898,7 @@ class JsonSchemaProxyHandler {
|
|||||||
deleteProperty(target, property) {
|
deleteProperty(target, property) {
|
||||||
const required = (
|
const required = (
|
||||||
(typeof target === 'object' && target !== null) ?
|
(typeof target === 'object' && target !== null) ?
|
||||||
(Array.isArray(target) || this._schema.isObjectPropertyRequired(property)) :
|
(!Array.isArray(target) && this._schema.isObjectPropertyRequired(property)) :
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
if (required) {
|
if (required) {
|
||||||
|
@ -945,7 +945,7 @@ function testProxy1() {
|
|||||||
tests: [
|
tests: [
|
||||||
{error: false, value: ['default'], action: (value) => { value[0] = 'string'; }},
|
{error: false, value: ['default'], action: (value) => { value[0] = 'string'; }},
|
||||||
{error: true, value: ['default'], action: (value) => { value[0] = null; }},
|
{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'; }},
|
||||||
{error: false, value: ['default'], action: (value) => {
|
{error: false, value: ['default'], action: (value) => {
|
||||||
value[1] = 'string';
|
value[1] = 'string';
|
||||||
|
Loading…
Reference in New Issue
Block a user