1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-29 12:59:56 +00:00

Fix jsonset crash when applied to primitive types

See https://talk.tiddlywiki.org/t/final-checks-before-release-of-v5-3-2/8560/7
This commit is contained in:
Jeremy Ruston 2023-11-29 12:06:40 +00:00
parent 622512c380
commit c282208668
2 changed files with 5 additions and 1 deletions

View File

@ -273,7 +273,10 @@ function setDataItem(data,indexes,value) {
lastIndex = $tw.utils.parseInt(lastIndex); lastIndex = $tw.utils.parseInt(lastIndex);
if(lastIndex < 0) { lastIndex = lastIndex + current.length }; if(lastIndex < 0) { lastIndex = lastIndex + current.length };
} }
// Only set indexes on objects and arrays
if(typeof current === "object") {
current[lastIndex] = value; current[lastIndex] = value;
}
return data; return data;
} }

View File

@ -124,6 +124,7 @@ describe("json filter tests", function() {
}); });
it("should support the jsonset operator", function() { it("should support the jsonset operator", function() {
expect(wiki.filterTiddlers("[jsonset[a],[aa]]")).toEqual(['"First"','"Second"','"Third"']);
expect(wiki.filterTiddlers("[{First}jsonset[]]")).toEqual(['{"a":"one","b":"","c":1.618,"d":{"e":"four","f":["five","six",true,false,null]}}']); expect(wiki.filterTiddlers("[{First}jsonset[]]")).toEqual(['{"a":"one","b":"","c":1.618,"d":{"e":"four","f":["five","six",true,false,null]}}']);
expect(wiki.filterTiddlers("[{First}jsonset[],[Antelope]]")).toEqual(['"Antelope"']); expect(wiki.filterTiddlers("[{First}jsonset[],[Antelope]]")).toEqual(['"Antelope"']);
expect(wiki.filterTiddlers("[{First}jsonset:number[],[not a number]]")).toEqual(['0']); expect(wiki.filterTiddlers("[{First}jsonset:number[],[not a number]]")).toEqual(['0']);