From 4d16546cdf60cdec670ea6f033253140f861ba55 Mon Sep 17 00:00:00 2001 From: Fabrice Bellard Date: Sat, 21 Mar 2026 15:53:25 +0100 Subject: [PATCH] fixed RegExp.escape --- TODO | 2 +- quickjs.c | 14 ++++++++------ test262_errors.txt | 2 -- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index 986a966..e0f6d60 100644 --- a/TODO +++ b/TODO @@ -63,4 +63,4 @@ Test262o: 0/11262 errors, 463 excluded Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch) Test262: -Result: 62/83394 errors, 3348 excluded, 6090 skipped +Result: 60/83394 errors, 3348 excluded, 6090 skipped diff --git a/quickjs.c b/quickjs.c index 5fae94b..d8ef72c 100644 --- a/quickjs.c +++ b/quickjs.c @@ -47318,9 +47318,10 @@ static JSValue js_regexp_escape(JSContext *ctx, JSValueConst this_val, JSValue str; StringBuffer b_s, *b = &b_s; JSString *p; - uint32_t c, i; + uint32_t c; char s[16]; - + int i, i0; + if (!JS_IsString(argv[0])) return JS_ThrowTypeError(ctx, "not a string"); str = JS_ToString(ctx, argv[0]); /* must call it to linearlize ropes */ @@ -47328,8 +47329,9 @@ static JSValue js_regexp_escape(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; p = JS_VALUE_GET_STRING(str); string_buffer_init2(ctx, b, 0, p->is_wide_char); - for (i = 0; i < p->len; i++) { - c = string_get(p, i); + for (i = 0; i < p->len; ) { + i0 = i; + c = string_getc(p, &i); if (c < 33) { if (c >= 9 && c <= 13) { string_buffer_putc8(b, '\\'); @@ -47341,7 +47343,7 @@ static JSValue js_regexp_escape(JSContext *ctx, JSValueConst this_val, if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { - if (i == 0) + if (i0 == 0) goto hex2; } else if (strchr(",-=<>#&!%:;@~'`\"", c)) { goto hex2; @@ -47357,7 +47359,7 @@ static JSValue js_regexp_escape(JSContext *ctx, JSValueConst this_val, snprintf(s, sizeof(s), "\\u%04x", c); string_buffer_puts8(b, s); } else { - string_buffer_putc16(b, c); + string_buffer_putc(b, c); } } JS_FreeValue(ctx, str); diff --git a/test262_errors.txt b/test262_errors.txt index a9c3174..309e927 100644 --- a/test262_errors.txt +++ b/test262_errors.txt @@ -23,8 +23,6 @@ test262/test/language/module-code/ambiguous-export-bindings/import-and-export-pr test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-export-star-as-from-and-import-star-as-and-export.js:74: SyntaxError: export 'foo' in module 'test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-import-star-as-and-export.js' is ambiguous test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-export-star-as-from.js:75: SyntaxError: export 'foo' in module 'test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-export-star-as-from.js' is ambiguous test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-import-star-as-and-export.js:74: SyntaxError: export 'foo' in module 'test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-import-star-as-and-export.js' is ambiguous -test262/test/staging/built-ins/RegExp/escape/surrogate-pair.js:9: Test262Error: Unescaped surrogate pair Expected SameValue(«"\\ud800\\udc00"», «"𐀀"») to be true -test262/test/staging/built-ins/RegExp/escape/surrogate-pair.js:9: strict mode: Test262Error: Unescaped surrogate pair Expected SameValue(«"\\ud800\\udc00"», «"𐀀"») to be true test262/test/staging/sm/Function/arguments-parameter-shadowing.js:14: Test262Error: Expected SameValue(«true», «false») to be true test262/test/staging/sm/Function/constructor-binding.js:11: Test262Error: Expected SameValue(«"function"», «"undefined"») to be true test262/test/staging/sm/Function/constructor-binding.js:11: strict mode: Test262Error: Expected SameValue(«"function"», «"undefined"») to be true