From e5c6459f7346c36ef31535992ebbd3b47e57d29e Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 27 Dec 2017 17:54:21 +0100 Subject: [PATCH] Fixed search matching array indexes --- src/jsoneditor/eson.js | 7 ++++--- src/jsoneditor/eson.test.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/jsoneditor/eson.js b/src/jsoneditor/eson.js index bb89f21..356401c 100644 --- a/src/jsoneditor/eson.js +++ b/src/jsoneditor/eson.js @@ -84,8 +84,8 @@ export function esonToJson (eson) { * Transform an eson object, traverse over the whole object (excluding the _meta) * objects, and allow replacing Objects/Arrays/values * @param {ESON} eson - * @param {function (eson, path)} callback - * @param {Path} path + * @param {function (ESON, Path) : ESON} callback + * @param {Path} [path] * @return {ESON} */ export function transform (eson, callback, path = []) { @@ -243,7 +243,8 @@ export function search (eson, text) { // check property name const prop = last(path) - if (typeof prop === 'string' && text !== '' && containsCaseInsensitive(prop, text)) { + if (text !== '' && containsCaseInsensitive(prop, text) && + getIn(eson, initial(path))[META].type === 'Object') { // parent must be an Object const searchState = isEmpty(matches) ? 'active' : 'normal' matches.push({path, area: 'property'}) updatedValue = setIn(updatedValue, [META, 'searchProperty'], searchState) diff --git a/src/jsoneditor/eson.test.js b/src/jsoneditor/eson.test.js index 926468f..57525e6 100644 --- a/src/jsoneditor/eson.test.js +++ b/src/jsoneditor/eson.test.js @@ -268,6 +268,21 @@ test('search', () => { assertDeepEqualEson(esonWithSearch, expected) }) +test('search number', () => { + const eson = jsonToEson({ + "2": "two", + "arr": ["a", "b", "c", "2"] + }) + const result = search(eson, '2') + const matches = result.searchResult.matches + + // should not match an array index, only props and values + expect(matches).toEqual([ + {path: ['2'], area: 'property'}, + {path: ['arr', '3'], area: 'value'} + ]) +}) + test('nextSearchResult', () => { const eson = jsonToEson({ "obj": {