diff --git a/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Libraries/LibJS/Runtime/RegExpPrototype.cpp index 0b5c93b72f5..f033e36ae6c 100644 --- a/Libraries/LibJS/Runtime/RegExpPrototype.cpp +++ b/Libraries/LibJS/Runtime/RegExpPrototype.cpp @@ -76,7 +76,7 @@ static ThrowCompletionOr 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 }; diff --git a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.hasIndices.js b/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.hasIndices.js index c2761b19711..a264e7be723 100644 --- a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.hasIndices.js +++ b/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.hasIndices.js @@ -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]); });