From f6dfe874db2518b3aba4d53939962ca9b467fe41 Mon Sep 17 00:00:00 2001 From: jos Date: Mon, 17 Oct 2016 20:38:35 +0200 Subject: [PATCH] Fixed action menu of root node not working --- src/jsonData.js | 4 ++++ test/jsonData.test.js | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/jsonData.js b/src/jsonData.js index 8b186e8..595fc6b 100644 --- a/src/jsonData.js +++ b/src/jsonData.js @@ -619,6 +619,10 @@ export function findPropertyIndex (object, prop) { * @return {Array} */ export function parseJSONPointer (pointer) { + if (pointer === '/') { + return [] + } + const path = pointer.split('/') path.shift() // remove the first empty entry diff --git a/test/jsonData.test.js b/test/jsonData.test.js index 5657e93..297a6d9 100644 --- a/test/jsonData.test.js +++ b/test/jsonData.test.js @@ -285,6 +285,8 @@ test('parseJSONPointer', t => { t.deepEqual(parseJSONPointer('/obj/a'), ['obj', 'a']) t.deepEqual(parseJSONPointer('/arr/-'), ['arr', '-']) t.deepEqual(parseJSONPointer('/foo/~1~0 ~0~1'), ['foo', '/~ ~/']) + t.deepEqual(parseJSONPointer('/obj'), ['obj']) + t.deepEqual(parseJSONPointer('/'), []) }) test('compileJSONPointer', t => {