Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix regexp split with zero-length capture group #566

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -43835,9 +43835,14 @@ static JSValue js_regexp_Symbol_split(JSContext *ctx, JSValue this_val,
if (js_get_length64(ctx, &numberOfCaptures, z))
goto exception;
for(i = 1; i < numberOfCaptures; i++) {
sub = JS_ToStringFree(ctx, JS_GetPropertyInt64(ctx, z, i));
sub = JS_GetPropertyInt64(ctx, z, i);
if (JS_IsException(sub))
goto exception;
if (!JS_IsUndefined(sub)) {
sub = JS_ToStringFree(ctx, sub);
if (JS_IsException(sub))
goto exception;
}
if (JS_DefinePropertyValueInt64(ctx, A, lengthA++, sub, JS_PROP_C_W_E | JS_PROP_THROW) < 0)
goto exception;
if (lengthA == lim)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ function test_regexp()
assert(a, ["a", undefined]);
a = /(?:|[\w])+([0-9])/.exec("123a23");
assert(a, ["123a23", "3"]);
a = "ab".split(/(c)*/);
assert(a, ["a", undefined, "b"]);
}

function test_symbol()
Expand Down
Loading