ref: d4a599edead399bc3fd7261d7c58fe14f66d8a47
parent: c3ce563aa92267b60017c1ec7854fe1baae1f94a
author: Tor Andersson <tor.andersson@artifex.com>
date: Thu Jul 8 14:13:35 EDT 2021
Issue 150: Fix regexp.exec bugs.
--- a/jsregexp.c
+++ b/jsregexp.c
@@ -53,25 +53,27 @@
void js_RegExp_prototype_exec(js_State *J, js_Regexp *re, const char *text)
{
+ const char *haystack;
int result;
int i;
int opts;
Resub m;
+ haystack = text;
opts = 0;
if (re->flags & JS_REGEXP_G) {
- if (re->last > strlen(text)) {
+ if (re->last > strlen(haystack)) {
re->last = 0;
js_pushnull(J);
return;
}
if (re->last > 0) {
- text += re->last;
+ haystack = text + re->last;
opts |= REG_NOTBOL;
}
}
- result = js_regexec(re->prog, text, &m, opts);
+ result = js_regexec(re->prog, haystack, &m, opts);
if (result < 0)
js_error(J, "regexec failed");
if (result == 0) {
@@ -85,7 +87,7 @@
js_setindex(J, -2, i);
}
if (re->flags & JS_REGEXP_G)
- re->last = re->last + (m.sub[0].ep - text);
+ re->last = m.sub[0].ep - text;
return;
}