1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-24 00:50:28 +00:00

Fix json operators retrieving properties of strings and numbers

Fixes #7160
This commit is contained in:
jeremy@jermolene.com 2022-12-30 15:28:34 +00:00
parent 0b39e47ce8
commit 3bdc18ab84
2 changed files with 7 additions and 1 deletions

View File

@ -176,7 +176,11 @@ function getDataItem(data,indexes) {
var item = data;
for(var i=0; i<indexes.length; i++) {
if(item !== undefined) {
item = item[indexes[i]];
if(item !== null && ["number","string","boolean"].indexOf(typeof item) === -1) {
item = item[indexes[i]];
} else {
item = undefined;
}
}
}
return item;

View File

@ -41,7 +41,9 @@ describe("json filter tests", function() {
expect(wiki.filterTiddlers("[{Second}jsonget[]]")).toEqual(["une","deux","trois","quatre","cinq"]);
expect(wiki.filterTiddlers("[{First}jsonget[]]")).toEqual(["one","","1.618","four","five","six","true","false","null"]);
expect(wiki.filterTiddlers("[{First}jsonget[a]]")).toEqual(["one"]);
expect(wiki.filterTiddlers("[{First}jsonget[a],[fixed]]")).toEqual([]);
expect(wiki.filterTiddlers("[{First}jsonget[b]]")).toEqual([""]);
expect(wiki.filterTiddlers("[{First}jsonget[c]]")).toEqual(["1.618"]);
expect(wiki.filterTiddlers("[{First}jsonget[missing-property]]")).toEqual([]);
expect(wiki.filterTiddlers("[{First}jsonget[d]]")).toEqual(["four","five","six","true","false","null"]);
expect(wiki.filterTiddlers("[{First}jsonget[d],[e]]")).toEqual(["four"]);