]> git.kaiwu.me - quickjs.git/commitdiff
\x{N} is a syntax error
authorFabrice Bellard <fabrice@bellard.org>
Mon, 22 Dec 2025 14:05:37 +0000 (15:05 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Mon, 22 Dec 2025 14:05:37 +0000 (15:05 +0100)
libregexp.c

index 42acae877595786c80d0e567150687d694ab38e1..9d9e3611300c6e878c263aac7761848319b8e398 100644 (file)
@@ -757,9 +757,21 @@ int lre_parse_escape(const uint8_t **pp, int allow_utf16)
         c = '\v';
         break;
     case 'x':
+        {
+            int h0, h1;
+
+            h0 = from_hex(*p++);
+            if (h0 < 0)
+                return -1;
+            h1 = from_hex(*p++);
+            if (h1 < 0)
+                return -1;
+            c = (h0 << 4) | h1;
+        }
+        break;
     case 'u':
         {
-            int h, n, i;
+            int h, i;
             uint32_t c1;
 
             if (*p == '{' && allow_utf16) {
@@ -777,14 +789,8 @@ int lre_parse_escape(const uint8_t **pp, int allow_utf16)
                 }
                 p++;
             } else {
-                if (c == 'x') {
-                    n = 2;
-                } else {
-                    n = 4;
-                }
-
                 c = 0;
-                for(i = 0; i < n; i++) {
+                for(i = 0; i < 4; i++) {
                     h = from_hex(*p++);
                     if (h < 0) {
                         return -1;