]> git.kaiwu.me - quickjs.git/commitdiff
regexp: fix non greedy quantizers with zero length matches
authorFabrice Bellard <fabrice@bellard.org>
Thu, 30 May 2024 14:41:37 +0000 (16:41 +0200)
committerFabrice Bellard <fabrice@bellard.org>
Thu, 30 May 2024 14:41:37 +0000 (16:41 +0200)
libregexp.c
tests/test_builtin.js

index 1091506feddce322eee090df5360b9e225c169eb..a2d56a7d09bc9cfcd5f9e8454819006ee4514896 100644 (file)
@@ -1488,15 +1488,13 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
 
                 if (dbuf_error(&s->byte_code))
                     goto out_of_memory;
-                /* the spec tells that if there is no advance when
-                   running the atom after the first quant_min times,
-                   then there is no match. We remove this test when we
-                   are sure the atom always advances the position. */
-                add_zero_advance_check = re_need_check_advance(s->byte_code.buf + last_atom_start,
-                                                               s->byte_code.size - last_atom_start);
-            } else {
-                add_zero_advance_check = FALSE;
             }
+            /* the spec tells that if there is no advance when
+               running the atom after the first quant_min times,
+               then there is no match. We remove this test when we
+               are sure the atom always advances the position. */
+            add_zero_advance_check = re_need_check_advance(s->byte_code.buf + last_atom_start,
+                                                           s->byte_code.size - last_atom_start);
 
             {
                 int len, pos;
index 03a56accfdd9f6051bdbd4a0df5f36ad4c370d5a..15cd18943b5437a2732451b24e59db577fd0b5df 100644 (file)
@@ -678,6 +678,8 @@ function test_regexp()
     assert(a, ["a", undefined]);
     a = /(?:|[\w])+([0-9])/.exec("123a23");
     assert(a, ["123a23", "3"]);
+    a = /()*?a/.exec(",");
+    assert(a, null);
 }
 
 function test_symbol()