diff options
-rw-r--r-- | jimregexp.c | 12 | ||||
-rw-r--r-- | tests/regmin.test | 8 |
2 files changed, 15 insertions, 5 deletions
diff --git a/jimregexp.c b/jimregexp.c index 8b78033..61fbb52 100644 --- a/jimregexp.c +++ b/jimregexp.c @@ -1505,14 +1505,16 @@ static int regmatch(regex_t *preg, const int *prog) min = (OP(scan) == STARMIN) ? 0 : 1; save = preg->reginput; max = regrepeat(preg, OPERAND(scan)); - while (min < max) { + while (min <= max) { int ch; - preg->reginput = save + min; + preg->reginput = save + utf8_index(save, min); reg_utf8_tounicode_case(preg->reginput, &ch, (preg->cflags & REG_ICASE)); /* If it could work, try it. */ - if (reg_iseol(preg, nextch) || ch == nextch) - if (regmatch(preg, next)) + if (reg_iseol(preg, nextch) || ch == nextch) { + if (regmatch(preg, next)) { return(1); + } + } /* Couldn't or didn't, add one more */ min++; } @@ -1539,6 +1541,7 @@ static int regmatch(regex_t *preg, const int *prog) no = regrepeat(preg, OPERAND(scan)); while (no >= min) { int ch; + preg->reginput = save + utf8_index(save, no); reg_utf8_tounicode_case(preg->reginput, &ch, (preg->cflags & REG_ICASE)); /* If it could work, try it. */ if (reg_iseol(preg, nextch) || ch == nextch) @@ -1546,7 +1549,6 @@ static int regmatch(regex_t *preg, const int *prog) return(1); /* Couldn't or didn't -- back up. */ no--; - preg->reginput = save + no; } return(0); } diff --git a/tests/regmin.test b/tests/regmin.test index 5ffe808..8ff1eb2 100644 --- a/tests/regmin.test +++ b/tests/regmin.test @@ -36,4 +36,12 @@ test regexpmin-1.8 {Minimal html} { regexp -inline {<(.+?)>} <foo><bar><grill> } {<foo> foo} +test regexpmin-2.1 {utf8 repeat} { + regexp -inline {a\u00df+} a\udf\udf\udf\udf\ub5z +} "a\udf\udf\udf\udf" + +test regexpmin-2.2 {utf8 min repeat} { + regexp -inline {a\u00df+?} a\udf\udf\udf\udf\ub5z +} "a\udf" + testreport |