summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/Parser
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-09-12 17:47:58 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-12 21:34:57 +0200
commit13c67f99206f818c364207f9ff3c7b9a06032ae3 (patch)
tree8c363216089e1a5a98570e914f32625b307b64c9 /Userland/Libraries/LibWeb/CSS/Parser
parent83cd2eef8f3e90b7dc8d89d938290cabb1ffea41 (diff)
downloadserenity-13c67f99206f818c364207f9ff3c7b9a06032ae3.zip
LibWeb: Ignore vendor-prefixed pseudo-element/classes in selectors
Our debug logging when we fail to parse a legitimate selector, is less useful when it's hidden among selectors that don't parse because they contain vendor-prefixed pseudo-elements and classes. So, now we specifically ignore these and don't produce a log message.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/Parser')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp18
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.h1
2 files changed, 17 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index e634822f8a..a8c6ff4d39 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -491,6 +491,8 @@ Result<Selector::SimpleSelector, Parser::SelectorParsingResult> Parser::parse_si
}
auto pseudo_name = name_token.token().ident();
+ if (has_ignored_vendor_prefix(pseudo_name))
+ return SelectorParsingResult::IncludesIgnoredVendorPrefix;
if (pseudo_name.equals_ignoring_case("after")) {
simple_selector.pseudo_element = Selector::SimpleSelector::PseudoElement::After;
@@ -518,6 +520,9 @@ Result<Selector::SimpleSelector, Parser::SelectorParsingResult> Parser::parse_si
if (pseudo_class_token.is(Token::Type::Ident)) {
auto pseudo_name = pseudo_class_token.token().ident();
+ if (has_ignored_vendor_prefix(pseudo_name))
+ return SelectorParsingResult::IncludesIgnoredVendorPrefix;
+
if (pseudo_name.equals_ignoring_case("active")) {
simple_selector.pseudo_class.type = Selector::SimpleSelector::PseudoClass::Type::Active;
} else if (pseudo_name.equals_ignoring_case("checked")) {
@@ -1223,8 +1228,17 @@ RefPtr<CSSRule> Parser::convert_to_rule(NonnullRefPtr<StyleRule> rule)
} else {
auto prelude_stream = TokenStream(rule->m_prelude);
auto selectors = parse_a_selector(prelude_stream);
- if (selectors.is_error() || selectors.value().is_empty()) {
- dbgln("CSSParser: style rule selectors invalid; discarding.");
+
+ if (selectors.is_error()) {
+ if (selectors.error() != SelectorParsingResult::IncludesIgnoredVendorPrefix) {
+ dbgln("CSSParser: style rule selectors invalid; discarding.");
+ prelude_stream.dump_all_tokens();
+ }
+ return {};
+ }
+
+ if (selectors.value().is_empty()) {
+ dbgln("CSSParser: empty selector; discarding.");
prelude_stream.dump_all_tokens();
return {};
}
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
index bad9bd0a2c..50a344ce4d 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
@@ -102,6 +102,7 @@ public:
private:
enum class SelectorParsingResult {
Done,
+ IncludesIgnoredVendorPrefix,
SyntaxError,
};