diff --git a/src/mujs/VERSION b/src/mujs/VERSION index 372a573..dbc2e36 100644 --- a/src/mujs/VERSION +++ b/src/mujs/VERSION @@ -1 +1 @@ -commit 0b4ed7e4ba37030fdd00f6a17b6de75cd7d7954b +commit e892c9fdbbddba94e52f656ccb378ed4885e30cc diff --git a/src/mujs/jsregexp.c b/src/mujs/jsregexp.c index 85c4a0d..92527d3 100644 --- a/src/mujs/jsregexp.c +++ b/src/mujs/jsregexp.c @@ -67,7 +67,8 @@ void js_RegExp_prototype_exec(js_State *J, js_Regexp *re, const char *text) } if (re->last > 0) { haystack = text + re->last; - opts |= REG_NOTBOL; + if (!(re->flags & JS_REGEXP_M) || haystack[-1] != '\n') + opts |= REG_NOTBOL; } } @@ -115,7 +116,8 @@ static void Rp_test(js_State *J) } if (re->last > 0) { text += re->last; - opts |= REG_NOTBOL; + if (!(re->flags & JS_REGEXP_M) || text[-1] != '\n') + opts |= REG_NOTBOL; } } diff --git a/src/mujs/jsstring.c b/src/mujs/jsstring.c index 1ebe99a..7ccf7c3 100644 --- a/src/mujs/jsstring.c +++ b/src/mujs/jsstring.c @@ -417,6 +417,11 @@ static void Sp_toUpperCase(js_State *J) js_free(J, dst); } +static int isbol(js_Regexp *re, const char *text, const char *a) +{ + return a == text || ((re->flags & JS_REGEXP_M) && a[-1] == '\n'); +} + static int istrim(int c) { return c == 0x9 || c == 0xB || c == 0xC || c == 0x20 || c == 0xA0 || c == 0xFEFF || @@ -492,7 +497,7 @@ static void Sp_match(js_State *J) a = text; e = text + strlen(text); while (a <= e) { - if (js_doregexec(J, re->prog, a, &m, a > text ? REG_NOTBOL : 0)) + if (js_doregexec(J, re->prog, a, &m, isbol(re, text, a) ? 0 : REG_NOTBOL)) break; b = m.sub[0].sp; @@ -625,7 +630,7 @@ loop: else goto end; } - if (!js_doregexec(J, re->prog, source, &m, REG_NOTBOL)) + if (!js_doregexec(J, re->prog, source, &m, isbol(re, source0, source) ? 0 : REG_NOTBOL)) goto loop; } @@ -740,7 +745,7 @@ static void Sp_split_regexp(js_State *J) p = a = text; while (a < e) { - if (js_doregexec(J, re->prog, a, &m, a > text ? REG_NOTBOL : 0)) + if (js_doregexec(J, re->prog, a, &m, isbol(re, text, a) ? 0 : REG_NOTBOL)) break; /* no match */ b = m.sub[0].sp; diff --git a/src/mujs/regexp.c b/src/mujs/regexp.c index 26d534f..3e951e4 100644 --- a/src/mujs/regexp.c +++ b/src/mujs/regexp.c @@ -18,7 +18,7 @@ #define REG_MAXPROG (32 << 10) #endif #ifndef REG_MAXREC -#define REG_MAXREC 1024 +#define REG_MAXREC 4096 #endif #ifndef REG_MAXSPAN #define REG_MAXSPAN 64