From 76e8640c3137163b8f13a3cb99182fd6ca538486 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 6 May 2014 18:10:27 +0100 Subject: [PATCH] Fix problem with parsing lists contain non-breaking spaces Some of the time we need to treat non-breaking spaces as though they are not spaces (regexps treat them as spaces by default). --- boot/boot.js | 2 +- editions/test/tiddlers/tests/test-utils.js | 29 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 editions/test/tiddlers/tests/test-utils.js diff --git a/boot/boot.js b/boot/boot.js index 1d098429d..947784f7f 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -266,7 +266,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) { if(typeof value === "string") { - var memberRegExp = /(?:^|\s)(?:\[\[(.*?)\]\])(?=\s|$)|(\S+)/mg, + var memberRegExp = /(?:^|[^\S\xA0])(?:\[\[(.*?)\]\])(?=[^\S\xA0]|$)|([\S\xA0]+)/mg, results = [], match; do { diff --git a/editions/test/tiddlers/tests/test-utils.js b/editions/test/tiddlers/tests/test-utils.js new file mode 100644 index 000000000..a83214243 --- /dev/null +++ b/editions/test/tiddlers/tests/test-utils.js @@ -0,0 +1,29 @@ +/*\ +title: test-utils.js +type: application/javascript +tags: [[$:/tags/test-spec]] + +Tests various utility functions. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +describe("Utility tests", function() { + + it("should handle parsing a string array", function() { + expect($tw.utils.parseStringArray("Tiddler8")).toEqual(["Tiddler8"]); + expect($tw.utils.parseStringArray(" Tiddler8")).toEqual(["Tiddler8"]); + expect($tw.utils.parseStringArray("Tiddler8 ")).toEqual(["Tiddler8"]); + expect($tw.utils.parseStringArray("Tiddler8 two")).toEqual(["Tiddler8","two"]); + expect($tw.utils.parseStringArray(" Tiddler8 two ")).toEqual(["Tiddler8","two"]); + expect($tw.utils.parseStringArray(" Tidd\u00a0ler8 two ")).toEqual(["Tidd\u00a0ler8","two"]); + expect($tw.utils.parseStringArray(" [[Tidd\u00a0ler8]] two ")).toEqual(["Tidd\u00a0ler8","two"]); + }); + +}); + +})();