1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-02 18:23:28 +00:00

Fix bug with empty strings ignored in $tw.utils.stringifyList/parseStringArray

I will pull this out into a separate PR. Fixing it doesn't cause problems for the core but I imagine it might cause issues for 3rd party code.
This commit is contained in:
jeremy@jermolene.com 2022-05-05 08:16:20 +01:00
parent e99137f4cc
commit 35430d09ed
2 changed files with 5 additions and 3 deletions

View File

@ -375,7 +375,7 @@ $tw.utils.stringifyList = function(value) {
var result = new Array(value.length);
for(var t=0, l=value.length; t<l; t++) {
var entry = value[t] || "";
if(entry.indexOf(" ") !== -1) {
if(entry.indexOf(" ") !== -1 || entry === "") {
result[t] = "[[" + entry + "]]";
} else {
result[t] = entry;
@ -396,7 +396,7 @@ $tw.utils.parseStringArray = function(value, allowDuplicate) {
do {
match = memberRegExp.exec(value);
if(match) {
var item = match[1] || match[2];
var item = match[1] !== undefined ? match[1] : match[2];
if(item !== undefined && (!$tw.utils.hop(names,item) || allowDuplicate)) {
results.push(item);
names[item] = true;

View File

@ -20,6 +20,7 @@ describe("Utility tests", function() {
expect(psa(" Tiddler8")).toEqual(["Tiddler8"]);
expect(psa("Tiddler8 ")).toEqual(["Tiddler8"]);
expect(psa("Tiddler8 two")).toEqual(["Tiddler8","two"]);
expect(psa("Tiddler8 two [[]]")).toEqual(["Tiddler8","two",""]);
expect(psa(" Tiddler8 two ")).toEqual(["Tiddler8","two"]);
expect(psa(" Tidd\u00a0ler8 two ")).toEqual(["Tidd\u00a0ler8","two"]);
expect(psa(" [[Tidd\u00a0ler8]] two ")).toEqual(["Tidd\u00a0ler8","two"]);
@ -51,6 +52,7 @@ describe("Utility tests", function() {
it("should handle stringifying a string array", function() {
var str = $tw.utils.stringifyList;
expect(str([])).toEqual("");
expect(str([""])).toEqual("[[]]");
expect(str(["Tiddler8"])).toEqual("Tiddler8");
expect(str(["Tiddler8 "])).toEqual("[[Tiddler8 ]]");
expect(str(["A+B", "A-B", "A=B"])).toEqual("A+B A-B A=B");
@ -58,7 +60,7 @@ describe("Utility tests", function() {
// Starting special characters aren't treated specially,
// even though this makes a list incompatible with a filter parser.
expect(str(["+T", "-T", "~T", "=T", "$T"])).toEqual("+T -T ~T =T $T");
expect(str(["A", "", "B"])).toEqual("A B");
expect(str(["A", "", "B"])).toEqual("A [[]] B");
});
it("stringifyList shouldn't interfere with setting variables to negative numbers", function() {