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.
This commit is contained in:
Ali Mohammad Pur 2021-07-18 05:15:10 +04:30 committed by Ali Mohammad Pur
parent f364fcec5d
commit c85ab623c0
Notes: sideshowbarker 2024-07-18 08:47:23 +09:00

View File

@ -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;