1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-26 15:23:15 +00:00

Fix stringifying/parsing string arrays containing newlines

A very old bug.

Fixes the ActionListOpsWidget problem @btheado
This commit is contained in:
jeremy@jermolene.com 2022-05-10 10:22:35 +01:00
parent 0b11b499c2
commit a827290332
2 changed files with 4 additions and 2 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 || entry === "") {
if(entry === "" || /[^\S\xA0]/.test(entry)) {
result[t] = "[[" + entry + "]]";
} else {
result[t] = entry;
@ -390,7 +390,7 @@ $tw.utils.stringifyList = function(value) {
// Parse a string array from a bracketted list. For example "OneTiddler [[Another Tiddler]] LastOne"
$tw.utils.parseStringArray = function(value, allowDuplicate) {
if(typeof value === "string") {
var memberRegExp = /(?:^|[^\S\xA0])(?:\[\[(.*?)\]\])(?=[^\S\xA0]|$)|([\S\xA0]+)/mg,
var memberRegExp = /(?:^|[^\S\xA0])(?:\[\[([\s\S]*?)\]\])(?=[^\S\xA0]|$)|([\S\xA0]+)/mg,
results = [], names = {},
match;
do {

View File

@ -22,6 +22,7 @@ describe("Utility tests", function() {
expect(psa("Tiddler8 two")).toEqual(["Tiddler8","two"]);
expect(psa("Tiddler8 two [[]]")).toEqual(["Tiddler8","two",""]);
expect(psa(" Tiddler8 two ")).toEqual(["Tiddler8","two"]);
expect(psa(" [[Tidd\tler8]] [[spl\nit]]")).toEqual(["Tidd\tler8","spl\nit"]);
expect(psa(" Tidd\u00a0ler8 two ")).toEqual(["Tidd\u00a0ler8","two"]);
expect(psa(" [[Tidd\u00a0ler8]] two ")).toEqual(["Tidd\u00a0ler8","two"]);
});
@ -56,6 +57,7 @@ describe("Utility tests", function() {
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");
expect(str(["A\nB", "A\tB"])).toEqual("[[A\nB]] [[A\tB]]");
expect(str(["A B"])).toEqual("[[A B]]");
// Starting special characters aren't treated specially,
// even though this makes a list incompatible with a filter parser.