diff --git a/HISTORY.md b/HISTORY.md index 0cc1db6..018bd56 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,9 @@ https://github.com/josdejong/jsoneditor ## not yet published, version 6.4.0 - Replaces CSS with SASS internally, improvements in styling. Thanks @ppetkow. +- Fixed #761: JSON schema errors not rendered in the gutter for mode `code` + when the path contained a property with a forward slash, and errors not + clickable in the error table. ## 2019-08-15, version 6.3.0 diff --git a/src/js/util.js b/src/js/util.js index 8876065..a825b31 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -1140,7 +1140,7 @@ exports.getPositionForPath = function(text, paths) { paths.forEach(function (path) { var pathArr = me.parsePath(path); - var pointerName = pathArr.length ? "/" + pathArr.join("/") : ""; + var pointerName = exports.compileJSONPointer(pathArr); var pointer = jsmap.pointers[pointerName]; if (pointer) { result.push({ @@ -1155,6 +1155,21 @@ exports.getPositionForPath = function(text, paths) { } +/** + * Compile a JSON Pointer + * WARNING: this is an incomplete implementation + * @param {Array.} path + * @return {string} + */ +exports.compileJSONPointer = function (path) { + return path + .map(p => ('/' + String(p) + .replace(/~/g, '~0') + .replace(/\//g, '~1') + )) + .join(''); +}; + /** * Get the applied color given a color name or code * Source: https://stackoverflow.com/questions/6386090/validating-css-color-names/33184805 diff --git a/test/util.test.js b/test/util.test.js index 8e272bb..d1d8c84 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -450,5 +450,12 @@ describe('util', function () { assert.strictEqual(util.limitCharacters('hello world', 100), 'hello world'); }) + it('should compile a JSON pointer', function () { + assert.strictEqual(util.compileJSONPointer(['foo', 'bar']), '/foo/bar') + assert.strictEqual(util.compileJSONPointer(['foo', '/~ ~/']), '/foo/~1~0 ~0~1') + assert.strictEqual(util.compileJSONPointer(['']), '/') + assert.strictEqual(util.compileJSONPointer([]), '') + }); + // TODO: thoroughly test all util methods }); \ No newline at end of file