LibJS: Create match indices based on code unit length

In Unicode mode, we were mixing code units (start_index) with code point
length (end_index).
This commit is contained in:
Timothy Flynn 2025-07-22 15:13:43 -04:00 committed by Jelle Raaijmakers
commit 04fe0c6aec
Notes: github-actions[bot] 2025-07-22 21:12:35 +00:00
2 changed files with 5 additions and 1 deletions

View file

@ -76,7 +76,7 @@ static ThrowCompletionOr<void> increment_last_index(VM& vm, Object& regexp_objec
struct Match {
static Match create(regex::Match const& match)
{
return { match.global_offset, match.global_offset + match.view.length() };
return { match.global_offset, match.global_offset + match.view.length_in_code_units() };
}
size_t start_index { 0 };

View file

@ -50,4 +50,8 @@ test("basic functionality", () => {
var result = regex.exec("let foo").indices;
expect(result.groups).toEqual({ keyword: [0, 3], id: [4, 7] });
}
regex = /🍕/du;
expect(regex.hasIndices).toBeTrue();
expect(regex.exec("🍕").indices[0]).toEqual([0, 2]);
});