diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-07-18 05:15:10 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-18 21:10:55 +0430 |
commit | c85ab623c055aef73185400a5ba9006c8f8a87d5 (patch) | |
tree | 3fe65a0a4328ca2ead65d71429f2b7035dfe18ea /Userland/Libraries/LibJS/Runtime | |
parent | f364fcec5da902ca8ae84dc0bca0f23533cebaa4 (diff) | |
download | serenity-c85ab623c055aef73185400a5ba9006c8f8a87d5.zip |
LibJS: Use a Utf8View on the subject if the regex has the unicode flag
This makes LibRegex behave (more) correctly with regards to matching
unicode code points.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp index 5881153ce9..c3c18e9251 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp @@ -240,7 +240,12 @@ static Value regexp_builtin_exec(GlobalObject& global_object, RegExpObject& rege } regex.start_offset = last_index; - result = regex.match(string); + // FIXME: JavaScript strings are UTF-16, update this if the backing storage + // encoding changes for spec compliance reasons. + if (unicode) + result = regex.match(Utf8View { string }); + else + result = regex.match(string); if (result.success) break; |