Fix json schema array properties (#1709)
* Fix proxy array properties being handled incorrectly * Add tests to check array properties
This commit is contained in:
parent
54e102f343
commit
900bceda47
@ -852,11 +852,12 @@ 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) {
|
if (index === null) {
|
||||||
// Note: this does not currently wrap mutating functions like push, pop, shift, unshift, splice
|
// Note: this does not currently wrap mutating functions like push, pop, shift, unshift, splice
|
||||||
return target[property];
|
return target[property];
|
||||||
}
|
}
|
||||||
|
property = index;
|
||||||
propertySchema = this._schema.getArrayItemSchema(property);
|
propertySchema = this._schema.getArrayItemSchema(property);
|
||||||
} else {
|
} else {
|
||||||
propertySchema = this._schema.getObjectPropertySchema(property);
|
propertySchema = this._schema.getObjectPropertySchema(property);
|
||||||
|
@ -946,7 +946,12 @@ function testProxy1() {
|
|||||||
{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: true, 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) => {
|
||||||
|
value[1] = 'string';
|
||||||
|
if (value.length !== 2) { throw new Error(`Invalid length; expected=2; actual=${value.length}`); }
|
||||||
|
if (typeof value.push !== 'function') { throw new Error(`Invalid push; expected=function; actual=${typeof value.push}`); }
|
||||||
|
}}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user