Fixed #663 and #682: JSONEditor not being able to handle JSON schema validation errors when the root of the document is an Array

This commit is contained in:
jos 2019-04-10 12:23:13 +02:00
parent d51090b7c9
commit 70b7e7914b
3 changed files with 12 additions and 4 deletions

View File

@ -3,6 +3,12 @@
https://github.com/josdejong/jsoneditor https://github.com/josdejong/jsoneditor
## not yet published, version 5.32.4
- Fixed #663 and #682: JSONEditor not being able to handle JSON schema
validation errors when the root of the document is an Array. Thanks @DusuWen.
## 2018-04-04, version 5.32.3 ## 2018-04-04, version 5.32.3
- Fix #684: `const` used in bundled library. - Fix #684: `const` used in bundled library.

View File

@ -778,7 +778,7 @@ exports.parsePath = function parsePath(jsonPath) {
i++; i++;
path.push(parseProperty()); path.push(parseProperty());
} }
else if (i > 0 && jsonPath[i] === '[') { else if (jsonPath[i] === '[') {
i++; i++;
if (jsonPath[i] === '\'' || jsonPath[i] === '"') { if (jsonPath[i] === '\'' || jsonPath[i] === '"') {

View File

@ -104,6 +104,7 @@ describe('util', function () {
assert.deepStrictEqual(util.stringifyPath(['foo', 2]), '.foo[2]'); assert.deepStrictEqual(util.stringifyPath(['foo', 2]), '.foo[2]');
assert.deepStrictEqual(util.stringifyPath(['foo', 2, 'bar']), '.foo[2].bar'); assert.deepStrictEqual(util.stringifyPath(['foo', 2, 'bar']), '.foo[2].bar');
assert.deepStrictEqual(util.stringifyPath(['foo', 2, 'bar_baz']), '.foo[2].bar_baz'); assert.deepStrictEqual(util.stringifyPath(['foo', 2, 'bar_baz']), '.foo[2].bar_baz');
assert.deepStrictEqual(util.stringifyPath([2]), '[2]');
assert.deepStrictEqual(util.stringifyPath(['foo', 'prop-with-hyphens']), '.foo["prop-with-hyphens"]'); assert.deepStrictEqual(util.stringifyPath(['foo', 'prop-with-hyphens']), '.foo["prop-with-hyphens"]');
assert.deepStrictEqual(util.stringifyPath(['foo', 'prop with spaces']), '.foo["prop with spaces"]'); assert.deepStrictEqual(util.stringifyPath(['foo', 'prop with spaces']), '.foo["prop with spaces"]');
}) })
@ -119,15 +120,16 @@ describe('util', function () {
assert.deepStrictEqual(util.parsePath('.foo["prop with . dot"]'), ['foo', 'prop with . dot']); assert.deepStrictEqual(util.parsePath('.foo["prop with . dot"]'), ['foo', 'prop with . dot']);
assert.deepStrictEqual(util.parsePath('.foo["prop with ] character"]'), ['foo', 'prop with ] character']); assert.deepStrictEqual(util.parsePath('.foo["prop with ] character"]'), ['foo', 'prop with ] character']);
assert.deepStrictEqual(util.parsePath('.foo[*].bar'), ['foo', '*', 'bar']); assert.deepStrictEqual(util.parsePath('.foo[*].bar'), ['foo', '*', 'bar']);
assert.deepStrictEqual(util.parsePath('[2]'), [2]);
}); });
it ('should throw an exception in case of an invalid path', function () { it ('should throw an exception in case of an invalid path', function () {
assert.throws(function () {util.parsePath('.')}, /Invalid JSON path: property name expected at index 1/); assert.throws(function () {util.parsePath('.')}, /Invalid JSON path: property name expected at index 1/);
assert.throws(function () {util.parsePath('[')}, /Invalid JSON path: unexpected character "\[" at index 0/); assert.throws(function () {util.parsePath('[')}, /Invalid JSON path: unexpected end, character ] expected/);
assert.throws(function () {util.parsePath('[]')}, /Invalid JSON path: unexpected character "\[" at index 0/); assert.throws(function () {util.parsePath('[]')}, /Invalid JSON path: array value expected at index 1/);
assert.throws(function () {util.parsePath('.foo[ ]')}, /Invalid JSON path: array value expected at index 7/); assert.throws(function () {util.parsePath('.foo[ ]')}, /Invalid JSON path: array value expected at index 7/);
assert.throws(function () {util.parsePath('.[]')}, /Invalid JSON path: property name expected at index 1/); assert.throws(function () {util.parsePath('.[]')}, /Invalid JSON path: property name expected at index 1/);
assert.throws(function () {util.parsePath('["23]')}, /Invalid JSON path: unexpected character "\[" at index 0/); assert.throws(function () {util.parsePath('["23]')}, /Invalid JSON path: unexpected end, character " expected/);
assert.throws(function () {util.parsePath('.foo bar')}, /Invalid JSON path: unexpected character " " at index 4/); assert.throws(function () {util.parsePath('.foo bar')}, /Invalid JSON path: unexpected character " " at index 4/);
}); });