Skip to content

Commit

Permalink
Fixed josdejong#663 and josdejong#682: JSONEditor not being able to h…
Browse files Browse the repository at this point in the history
…andle JSON schema validation errors when the root of the document is an Array
  • Loading branch information
josdejong committed Apr 10, 2019
1 parent d51090b commit 70b7e79
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
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

- Fix #684: `const` used in bundled library.
Expand Down
2 changes: 1 addition & 1 deletion src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ exports.parsePath = function parsePath(jsonPath) {
i++;
path.push(parseProperty());
}
else if (i > 0 && jsonPath[i] === '[') {
else if (jsonPath[i] === '[') {
i++;

if (jsonPath[i] === '\'' || jsonPath[i] === '"') {
Expand Down
8 changes: 5 additions & 3 deletions test/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe('util', function () {
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_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 spaces']), '.foo["prop with spaces"]');
})
Expand All @@ -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 ] character"]'), ['foo', 'prop with ] character']);
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 () {
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 character "\[" at index 0/);
assert.throws(function () {util.parsePath('[')}, /Invalid JSON path: unexpected end, character ] expected/);
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('.[]')}, /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/);
});

Expand Down

0 comments on commit 70b7e79

Please sign in to comment.