ref: 40556b31c6920491474a4e24784ed3b1c1c832de
parent: d2697fd6435d0ffaae5c424e00ccf3a4b5a21f56
author: Tor Andersson <tor.andersson@artifex.com>
date: Fri Jan 26 09:18:08 EST 2024
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!
--- a/jsstring.c
+++ b/jsstring.c
@@ -661,12 +661,14 @@
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 @@
c = m.sub[0].ep;
/* empty string at end of last match */
- if (b == p) {
+ if (b == c && b == p) {
++a;
continue;
}
@@ -713,6 +715,9 @@
int i, n;
js_newarray(J);
+
+ if (limit == 0)
+ return;
n = strlen(sep);