mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-24 10:37:20 +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:
parent
e99137f4cc
commit
35430d09ed
@ -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;
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user