From 337754ae64d0e86c43b7c0e3359bff026ecde906 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Sat, 12 Aug 2023 13:58:19 +0100 Subject: [PATCH] LibWeb: Add hack for `:host` in pseudo-class serialization The spec for this algorithm is quite outdated, we already have some other pseudo-classes in here which the spec doesn't cover. --- Userland/Libraries/LibWeb/CSS/Selector.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Selector.cpp b/Userland/Libraries/LibWeb/CSS/Selector.cpp index a312010d36..866fca850b 100644 --- a/Userland/Libraries/LibWeb/CSS/Selector.cpp +++ b/Userland/Libraries/LibWeb/CSS/Selector.cpp @@ -229,9 +229,22 @@ ErrorOr Selector::SimpleSelector::serialize() const auto& pseudo_class = this->pseudo_class(); auto metadata = pseudo_class_metadata(pseudo_class.type); - + // HACK: `:host()` has both a function and a non-function form, so handle that first. + // It's also not in the spec. + if (pseudo_class.type == PseudoClass::Host) { + if (pseudo_class.argument_selector_list.is_empty()) { + TRY(s.try_append(':')); + TRY(s.try_append(pseudo_class_name(pseudo_class.type))); + } else { + TRY(s.try_append(':')); + TRY(s.try_append(pseudo_class_name(pseudo_class.type))); + TRY(s.try_append('(')); + TRY(s.try_append(TRY(serialize_a_group_of_selectors(pseudo_class.argument_selector_list)))); + TRY(s.try_append(')')); + } + } // If the pseudo-class does not accept arguments append ":" (U+003A), followed by the name of the pseudo-class, to s. - if (metadata.is_valid_as_identifier) { + else if (metadata.is_valid_as_identifier) { TRY(s.try_append(':')); TRY(s.try_append(pseudo_class_name(pseudo_class.type))); }