Skip to content

Commit 36911f0

Browse files
author
Fabrice Bellard
committed
regexp: fix non greedy quantizers with zero length matches
1 parent d86aaf0 commit 36911f0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

libregexp.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -1488,15 +1488,13 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
14881488

14891489
if (dbuf_error(&s->byte_code))
14901490
goto out_of_memory;
1491-
/* the spec tells that if there is no advance when
1492-
running the atom after the first quant_min times,
1493-
then there is no match. We remove this test when we
1494-
are sure the atom always advances the position. */
1495-
add_zero_advance_check = re_need_check_advance(s->byte_code.buf + last_atom_start,
1496-
s->byte_code.size - last_atom_start);
1497-
} else {
1498-
add_zero_advance_check = FALSE;
14991491
}
1492+
/* the spec tells that if there is no advance when
1493+
running the atom after the first quant_min times,
1494+
then there is no match. We remove this test when we
1495+
are sure the atom always advances the position. */
1496+
add_zero_advance_check = re_need_check_advance(s->byte_code.buf + last_atom_start,
1497+
s->byte_code.size - last_atom_start);
15001498

15011499
{
15021500
int len, pos;

tests/test_builtin.js

+2
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,8 @@ function test_regexp()
678678
assert(a, ["a", undefined]);
679679
a = /(?:|[\w])+([0-9])/.exec("123a23");
680680
assert(a, ["123a23", "3"]);
681+
a = /()*?a/.exec(",");
682+
assert(a, null);
681683
}
682684

683685
function test_symbol()

0 commit comments

Comments
 (0)