LibWeb: Add name validation and document check to setAttribute

Co-authored-by: Rayyan Hamid <rayyanbwp@gmail.com>
Co-authored-by: Christian Ewing <u1273549@utah.edu>
Co-authored-by: Austin Fashimpaur <austin.fashimpaur@gmail.com>
This commit is contained in:
Alex 2024-04-18 23:18:23 -06:00 committed by Tim Flynn
commit 13abb1b2c7
Notes: sideshowbarker 2024-07-17 07:16:27 +09:00
6 changed files with 45 additions and 8 deletions

View file

@ -2628,12 +2628,13 @@ static inline bool is_valid_name_character(u32 code_point)
|| (code_point >= 0x203f && code_point <= 0x2040);
}
// https://www.w3.org/TR/xml/#NT-Name
bool Document::is_valid_name(String const& name)
{
auto code_points = Utf8View { name };
auto it = code_points.begin();
if (code_points.is_empty())
if (name.is_empty())
return false;
auto code_points = name.code_points();
auto it = code_points.begin();
if (!is_valid_name_start_character(*it))
return false;