]> git.kaiwu.me - quickjs.git/commitdiff
fixed regexp unicode set parsing (#520)
authorFabrice Bellard <fabrice@bellard.org>
Sat, 26 Sep 2026 11:01:30 +0000 (13:01 +0200)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 26 Sep 2026 11:01:45 +0000 (13:01 +0200)
libregexp.c
tests/test_builtin.js

index c387f004387d546faf418abfe0b1227d5763c2dc..b231e95343ed2fde6062297420cc2cae0f4f5dd7 100644 (file)
@@ -1183,7 +1183,7 @@ static int get_class_atom(REParseState *s, REStringList *cr,
     case '^':
     case '`':
     case '~':
-        if (s->unicode_sets && p[1] == c) {
+        if (inclass && s->unicode_sets && p[1] == c) {
             /* forbidden double characters */
             return re_parse_error(s, "invalid class set operation in regular expression");
         }
@@ -1198,7 +1198,7 @@ static int get_class_atom(REParseState *s, REStringList *cr,
     case '/':
     case '-':
     case '|':
-        if (s->unicode_sets) {
+        if (inclass && s->unicode_sets) {
             /* invalid characters in unicode sets */
             return re_parse_error(s, "invalid character in class in regular expression");
         }
index 14bcc06d307ed8bcd0056a829f3c5867fc212240..c20d740c6709d0aeb1a1bdee160eec5df6f20599 100644 (file)
@@ -805,6 +805,9 @@ function test_regexp()
     a = a.exec("\u{10000}_\u{10000}");
     assert(a.indices[0][0], 0);
     assert(a.indices[0][1], 2);
+
+    /* syntax check */
+    assert(/-&&/v.test("-&&"), true);
 }
 
 function test_symbol()