mirror of
https://github.com/ccxvii/mujs.git
synced 2026-02-05 17:29:43 +08:00
Issue #130: Fix bug with String.prototype.split(RegExp).
The "empty string at end of last match" should only trigger if the match is empty!
This commit is contained in:
@@ -661,12 +661,14 @@ static void Sp_split_regexp(js_State *J)
|
||||
js_newarray(J);
|
||||
len = 0;
|
||||
|
||||
if (limit == 0)
|
||||
return;
|
||||
|
||||
e = text + strlen(text);
|
||||
|
||||
/* splitting the empty string */
|
||||
if (e == text) {
|
||||
if (js_doregexec(J, re->prog, text, &m, 0)) {
|
||||
if (len == limit) return;
|
||||
js_pushliteral(J, "");
|
||||
js_setindex(J, -2, 0);
|
||||
}
|
||||
@@ -682,7 +684,7 @@ static void Sp_split_regexp(js_State *J)
|
||||
c = m.sub[0].ep;
|
||||
|
||||
/* empty string at end of last match */
|
||||
if (b == p) {
|
||||
if (b == c && b == p) {
|
||||
++a;
|
||||
continue;
|
||||
}
|
||||
@@ -714,6 +716,9 @@ static void Sp_split_string(js_State *J)
|
||||
|
||||
js_newarray(J);
|
||||
|
||||
if (limit == 0)
|
||||
return;
|
||||
|
||||
n = strlen(sep);
|
||||
|
||||
/* empty string */
|
||||
|
||||
Reference in New Issue
Block a user