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

LibWeb: Throw SyntaxError on bogus querySelector{,All} input selector

This commit is contained in:
Andreas Kling 2021-09-11 22:54:26 +02:00
parent 935075c26e
commit 0398089275
2 changed files with 6 additions and 6 deletions

View file

@ -11,11 +11,11 @@
namespace Web::DOM { namespace Web::DOM {
RefPtr<Element> ParentNode::query_selector(const StringView& selector_text) ExceptionOr<RefPtr<Element>> ParentNode::query_selector(StringView selector_text)
{ {
auto maybe_selectors = parse_selector(CSS::ParsingContext(*this), selector_text); auto maybe_selectors = parse_selector(CSS::ParsingContext(*this), selector_text);
if (!maybe_selectors.has_value()) if (!maybe_selectors.has_value())
return {}; return DOM::SyntaxError::create("Failed to parse selector");
auto selectors = maybe_selectors.value(); auto selectors = maybe_selectors.value();
@ -36,11 +36,11 @@ RefPtr<Element> ParentNode::query_selector(const StringView& selector_text)
return result; return result;
} }
NonnullRefPtrVector<Element> ParentNode::query_selector_all(const StringView& selector_text) ExceptionOr<NonnullRefPtrVector<Element>> ParentNode::query_selector_all(StringView selector_text)
{ {
auto maybe_selectors = parse_selector(CSS::ParsingContext(*this), selector_text); auto maybe_selectors = parse_selector(CSS::ParsingContext(*this), selector_text);
if (!maybe_selectors.has_value()) if (!maybe_selectors.has_value())
return {}; return DOM::SyntaxError::create("Failed to parse selector");
auto selectors = maybe_selectors.value(); auto selectors = maybe_selectors.value();

View file

@ -22,8 +22,8 @@ public:
RefPtr<Element> last_element_child(); RefPtr<Element> last_element_child();
u32 child_element_count() const; u32 child_element_count() const;
RefPtr<Element> query_selector(const StringView&); ExceptionOr<RefPtr<Element>> query_selector(StringView);
NonnullRefPtrVector<Element> query_selector_all(const StringView&); ExceptionOr<NonnullRefPtrVector<Element>> query_selector_all(StringView);
protected: protected:
ParentNode(Document& document, NodeType type) ParentNode(Document& document, NodeType type)