diff --git a/core/modules/filters/strings.js b/core/modules/filters/strings.js index 27273ca41..947dad2f5 100644 --- a/core/modules/filters/strings.js +++ b/core/modules/filters/strings.js @@ -70,7 +70,7 @@ function makeStringReducingOperator(fnCalc,initialValue) { }); return [result.reduce(function(accumulator,currentValue) { return fnCalc(accumulator,currentValue,operator.operand || ""); - },initialValue)]; + },initialValue) || ""]; }; } diff --git a/editions/test/tiddlers/tests/test-filters.js b/editions/test/tiddlers/tests/test-filters.js index b0de6f5f0..929abe93d 100644 --- a/editions/test/tiddlers/tests/test-filters.js +++ b/editions/test/tiddlers/tests/test-filters.js @@ -450,6 +450,10 @@ function runTests(wiki) { expect(wiki.filterTiddlers("[[John. Paul. George. Ringo.]] +[split[.]trim[]]").join(",")).toBe("John,Paul,George,Ringo,"); expect(wiki.filterTiddlers("John Paul George Ringo +[split[e]]").join(",")).toBe("John,Paul,G,org,,Ringo"); expect(wiki.filterTiddlers("John Paul George Ringo +[join[ ]split[e]join[ee]split[ ]]").join(",")).toBe("John,Paul,Geeorgee,Ringo"); + // Ensure that join doesn't return null if passed empty list + expect(wiki.filterTiddlers("Test +[butlast[]join[ ]]")).toEqual([""]); + // Ensure that join correctly handles empty strings in source + expect(wiki.filterTiddlers("[[]] Paul +[join[-]]").join(",")).toBe("-Paul"); expect(wiki.filterTiddlers("[[ John ]] [[Paul ]] [[ George]] Ringo +[trim[]join[-]]").join(",")).toBe("John-Paul-George-Ringo"); });