mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:37:35 +00:00
LibJS: Use Utf8View for string prefix checks
This commit replaces the usage of String::starts_with with Utf8View::starts_with, which first decodes the utf8 encoded string, and as such can take things like overlong encoded sequences into account (which could otherwise cause the prefix check to be inconsistent with the following code points check).
This commit is contained in:
parent
edecf8f6a3
commit
78f0cabb17
1 changed files with 6 additions and 5 deletions
|
@ -1213,13 +1213,14 @@ TriState abstract_relation(GlobalObject& global_object, bool left_first, Value l
|
|||
auto x_string = x_primitive.as_string().string();
|
||||
auto y_string = y_primitive.as_string().string();
|
||||
|
||||
if (x_string.starts_with(y_string))
|
||||
return TriState::False;
|
||||
if (y_string.starts_with(x_string))
|
||||
return TriState::True;
|
||||
|
||||
Utf8View x_code_points { x_string };
|
||||
Utf8View y_code_points { y_string };
|
||||
|
||||
if (x_code_points.starts_with(y_code_points))
|
||||
return TriState::False;
|
||||
if (y_code_points.starts_with(x_code_points))
|
||||
return TriState::True;
|
||||
|
||||
for (auto k = x_code_points.begin(), l = y_code_points.begin();
|
||||
k != x_code_points.end() && l != y_code_points.end();
|
||||
++k, ++l) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue