LibWeb: Reject more invalid pseudo-element selectors in KeyframeEffect

The old way this was written wouldn't actually check for the presence of
the two initial colons in the pseudo-element string.
This commit is contained in:
Matthew Olsson 2024-05-27 06:21:01 -07:00 committed by Andreas Kling
parent e188ab1493
commit 854d02fe10

View file

@ -761,16 +761,17 @@ WebIDL::ExceptionOr<void> KeyframeEffect::set_pseudo_element(Optional<String> ps
// DOMException with error name SyntaxError and leave the target pseudo-selector of this animation effect
// unchanged.
if (pseudo_element.has_value()) {
auto pseudo_element_without_colons = MUST(pseudo_element->replace("::"sv, ""sv, ReplaceMode::FirstOnly));
if (auto value = CSS::Selector::PseudoElement::from_string(pseudo_element_without_colons); value.has_value()) {
m_target_pseudo_selector = value;
} else {
return WebIDL::SyntaxError::create(realm, MUST(String::formatted("Invalid pseudo-element selector: \"{}\"", pseudo_element.value())));
if (pseudo_element->starts_with_bytes("::"sv)) {
if (auto value = CSS::Selector::PseudoElement::from_string(MUST(pseudo_element->substring_from_byte_offset(2))); value.has_value()) {
m_target_pseudo_selector = value;
return {};
}
}
} else {
m_target_pseudo_selector = {};
return WebIDL::SyntaxError::create(realm, MUST(String::formatted("Invalid pseudo-element selector: \"{}\"", pseudo_element.value())));
}
m_target_pseudo_selector = {};
return {};
}