1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:17:44 +00:00

LibWeb: Iterate codepoints instead of characters in is_valid_name

This commit is contained in:
Srikavin Ramkumar 2023-03-23 04:44:26 -04:00 committed by Tim Flynn
parent 1d7bad5347
commit 149e442c24

View file

@ -1882,14 +1882,17 @@ static inline bool is_valid_name_character(u32 code_point)
bool Document::is_valid_name(DeprecatedString const& name) bool Document::is_valid_name(DeprecatedString const& name)
{ {
if (name.is_empty()) auto code_points = Utf8View { name };
auto it = code_points.begin();
if (code_points.is_empty())
return false; return false;
if (!is_valid_name_start_character(name[0])) if (!is_valid_name_start_character(*it))
return false; return false;
++it;
for (size_t i = 1; i < name.length(); ++i) { for (; it != code_points.end(); ++it) {
if (!is_valid_name_character(name[i])) if (!is_valid_name_character(*it))
return false; return false;
} }