1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Fixed join filter operator to never returns null (#4396)

If the operator were passed an empty list, it would return null
which could cause some proceeding operators to crash.
This commit is contained in:
Cameron Fischer 2020-04-14 12:49:38 -04:00 committed by GitHub
parent 43fdb553b7
commit 65347ae858
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -70,7 +70,7 @@ function makeStringReducingOperator(fnCalc,initialValue) {
}); });
return [result.reduce(function(accumulator,currentValue) { return [result.reduce(function(accumulator,currentValue) {
return fnCalc(accumulator,currentValue,operator.operand || ""); return fnCalc(accumulator,currentValue,operator.operand || "");
},initialValue)]; },initialValue) || ""];
}; };
} }

View File

@ -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[.]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 +[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"); 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"); expect(wiki.filterTiddlers("[[ John ]] [[Paul ]] [[ George]] Ringo +[trim[]join[-]]").join(",")).toBe("John-Paul-George-Ringo");
}); });