From c282208668ee89af07b81cf93a21ba68430affc0 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 29 Nov 2023 12:06:40 +0000 Subject: [PATCH] Fix jsonset crash when applied to primitive types See https://talk.tiddlywiki.org/t/final-checks-before-release-of-v5-3-2/8560/7 --- core/modules/filters/json-ops.js | 5 ++++- editions/test/tiddlers/tests/test-json-filters.js | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/modules/filters/json-ops.js b/core/modules/filters/json-ops.js index 75a34e94a..0c58964eb 100644 --- a/core/modules/filters/json-ops.js +++ b/core/modules/filters/json-ops.js @@ -273,7 +273,10 @@ function setDataItem(data,indexes,value) { lastIndex = $tw.utils.parseInt(lastIndex); if(lastIndex < 0) { lastIndex = lastIndex + current.length }; } - current[lastIndex] = value; + // Only set indexes on objects and arrays + if(typeof current === "object") { + current[lastIndex] = value; + } return data; } diff --git a/editions/test/tiddlers/tests/test-json-filters.js b/editions/test/tiddlers/tests/test-json-filters.js index a8903970a..bfb8a4504 100644 --- a/editions/test/tiddlers/tests/test-json-filters.js +++ b/editions/test/tiddlers/tests/test-json-filters.js @@ -124,6 +124,7 @@ describe("json filter tests", 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[],[Antelope]]")).toEqual(['"Antelope"']); expect(wiki.filterTiddlers("[{First}jsonset:number[],[not a number]]")).toEqual(['0']);