Ver código fonte

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).
Idan Horowitz 4 anos atrás
pai
commit
78f0cabb17
1 arquivos alterados com 5 adições e 4 exclusões
  1. 5 4
      Userland/Libraries/LibJS/Runtime/Value.cpp

+ 5 - 4
Userland/Libraries/LibJS/Runtime/Value.cpp

@@ -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))
+        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_string.starts_with(x_string))
+        if (y_code_points.starts_with(x_code_points))
             return TriState::True;
 
-        Utf8View x_code_points { x_string };
-        Utf8View y_code_points { y_string };
         for (auto k = x_code_points.begin(), l = y_code_points.begin();
              k != x_code_points.end() && l != y_code_points.end();
              ++k, ++l) {