mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-28 13:18:19 +00:00
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:
parent
772479b334
commit
04fe0c6aec
Notes:
github-actions[bot]
2025-07-22 21:12:35 +00:00
Author: https://github.com/trflynn89
Commit: 04fe0c6aec
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5569
Reviewed-by: https://github.com/gmta ✅
2 changed files with 5 additions and 1 deletions
|
@ -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 };
|
||||
|
|
|
@ -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]);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue