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.
Jermolene-patch-1
Cameron Fischer 2020-04-14 12:49:38 -04:00 zatwierdzone przez GitHub
rodzic 43fdb553b7
commit 65347ae858
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 5 dodań i 1 usunięć

Wyświetl plik

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

Wyświetl plik

@ -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");
});