Skip to content

Commit ff3e935

Browse files
committed
Fix List to work with empty matches.
1 parent a97ba75 commit ff3e935

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

dev/src/helpers/BrowserSolver.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default class BrowserSolver {
8282

8383
let tool = this._req.tool;
8484
result.tool = { id: tool.id };
85-
if (!error && tool.input != null) {
85+
if (!error || error.warning && tool.input != null) {
8686
let str = Utils.unescSubstStr(tool.input);
8787
result.tool.result = (tool.id === "replace") ? this._getReplace(str) : this._getList(str);
8888
}
@@ -94,6 +94,7 @@ export default class BrowserSolver {
9494
}
9595

9696
_getList(str) {
97+
// TODO: should we move this into a worker?
9798
let source = this._req.text, result = "", repl, ref, trimR = 0, regex;
9899

99100
// build a RegExp without the global flag:
@@ -107,14 +108,14 @@ export default class BrowserSolver {
107108
trimR = str.length;
108109
str = "$&"+str;
109110
}
110-
while (true) {
111-
ref = source.replace(regex, "\b");
112-
let index = ref.indexOf("\b");
113-
if (index === -1 || ref.length > source.length) { break; }
111+
do {
112+
ref = source.replace(regex, "\b"); // bell char - just a placeholder to find
113+
let index = ref.indexOf("\b"), empty = (ref.length > source.length);
114+
if (index === -1) { break; }
114115
repl = source.replace(regex, str);
115116
result += repl.substr(index, repl.length-ref.length+1);
116-
source = ref.substr(index+1);
117-
}
117+
source = ref.substr(index+(empty?2:1));
118+
} while (source.length);
118119
if (trimR) { result = result.substr(0,result.length-trimR); }
119120
return result;
120121
}

dev/src/utils/Utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Utils.shorten = function (str, length, htmlSafe, tag="") {
8585
};
8686

8787
Utils.unescSubstStr = function(str) {
88+
if (!str) { return ""; }
8889
return str.replace(Utils.SUBST_ESC_RE, (a, b, c)=> Utils.SUBST_ESC_CHARS[b] || String.fromCharCode(parseInt(c, 16)) );
8990
};
9091

0 commit comments

Comments
 (0)