mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 14:19:48 +00:00
LibWeb: Perform DOMTokenList token validation in the correct order
This commit is contained in:
parent
ec1f7779cb
commit
0127190dcf
Notes:
github-actions[bot]
2024-07-25 04:44:23 +00:00
Author: https://github.com/tcl3
Commit: 0127190dcf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/817
4 changed files with 26 additions and 2 deletions
|
@ -3,3 +3,4 @@ element.classList after setting classList to "a": "a"
|
||||||
element.classList after setting className to "": ""
|
element.classList after setting className to "": ""
|
||||||
element.classList after setting to className to "a a b c": "a a b c"
|
element.classList after setting to className to "a a b c": "a a b c"
|
||||||
element.classList after setting to className to " a a b c ": " a a b c "
|
element.classList after setting to className to " a a b c ": " a a b c "
|
||||||
|
element.classList.replace(" ", "") throws "SyntaxError"
|
||||||
|
|
|
@ -12,6 +12,12 @@
|
||||||
println(`element.classList after setting to className to "a a b c": "${element.classList.toString()}"`);
|
println(`element.classList after setting to className to "a a b c": "${element.classList.toString()}"`);
|
||||||
element.className = " a a b c ";
|
element.className = " a a b c ";
|
||||||
println(`element.classList after setting to className to " a a b c ": "${element.classList.toString()}"`);
|
println(`element.classList after setting to className to " a a b c ": "${element.classList.toString()}"`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
element.classList.replace(" ", "");
|
||||||
|
} catch (e) {
|
||||||
|
println(`element.classList.replace(" ", "") throws "${e.name}"`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -192,9 +192,12 @@ WebIDL::ExceptionOr<bool> DOMTokenList::toggle(String const& token, Optional<boo
|
||||||
WebIDL::ExceptionOr<bool> DOMTokenList::replace(String const& token, String const& new_token)
|
WebIDL::ExceptionOr<bool> DOMTokenList::replace(String const& token, String const& new_token)
|
||||||
{
|
{
|
||||||
// 1. If either token or newToken is the empty string, then throw a "SyntaxError" DOMException.
|
// 1. If either token or newToken is the empty string, then throw a "SyntaxError" DOMException.
|
||||||
|
TRY(validate_token_not_empty(token));
|
||||||
|
TRY(validate_token_not_empty(new_token));
|
||||||
|
|
||||||
// 2. If either token or newToken contains any ASCII whitespace, then throw an "InvalidCharacterError" DOMException.
|
// 2. If either token or newToken contains any ASCII whitespace, then throw an "InvalidCharacterError" DOMException.
|
||||||
TRY(validate_token(token));
|
TRY(validate_token_not_whitespace(token));
|
||||||
TRY(validate_token(new_token));
|
TRY(validate_token_not_whitespace(new_token));
|
||||||
|
|
||||||
// 3. If this’s token set does not contain token, then return false.
|
// 3. If this’s token set does not contain token, then return false.
|
||||||
if (!contains(token))
|
if (!contains(token))
|
||||||
|
@ -264,9 +267,21 @@ void DOMTokenList::set_value(String const& value)
|
||||||
}
|
}
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> DOMTokenList::validate_token(StringView token) const
|
WebIDL::ExceptionOr<void> DOMTokenList::validate_token(StringView token) const
|
||||||
|
{
|
||||||
|
TRY(validate_token_not_empty(token));
|
||||||
|
TRY(validate_token_not_whitespace(token));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<void> DOMTokenList::validate_token_not_empty(StringView token) const
|
||||||
{
|
{
|
||||||
if (token.is_empty())
|
if (token.is_empty())
|
||||||
return WebIDL::SyntaxError::create(realm(), "Non-empty DOM tokens are not allowed"_fly_string);
|
return WebIDL::SyntaxError::create(realm(), "Non-empty DOM tokens are not allowed"_fly_string);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<void> DOMTokenList::validate_token_not_whitespace(StringView token) const
|
||||||
|
{
|
||||||
if (any_of(token, Infra::is_ascii_whitespace))
|
if (any_of(token, Infra::is_ascii_whitespace))
|
||||||
return WebIDL::InvalidCharacterError::create(realm(), "DOM tokens containing ASCII whitespace are not allowed"_fly_string);
|
return WebIDL::InvalidCharacterError::create(realm(), "DOM tokens containing ASCII whitespace are not allowed"_fly_string);
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -51,6 +51,8 @@ private:
|
||||||
virtual void visit_edges(Cell::Visitor&) override;
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> validate_token(StringView token) const;
|
WebIDL::ExceptionOr<void> validate_token(StringView token) const;
|
||||||
|
WebIDL::ExceptionOr<void> validate_token_not_empty(StringView token) const;
|
||||||
|
WebIDL::ExceptionOr<void> validate_token_not_whitespace(StringView token) const;
|
||||||
void run_update_steps();
|
void run_update_steps();
|
||||||
|
|
||||||
String serialize_ordered_set() const;
|
String serialize_ordered_set() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue