LibWeb/CSS: Keep invalid parts of <forgiving-selector-list>s around

Attempt 2! Reverts 2a5dbedad4

This time, set up a different combinator when producing a relative
invalid selector rather than a standalone one. This fixes the crash.

Original description below for simplicity because it still applies.

---

Selectors like `:is(.valid, &!?!?!invalid)` need to keep the invalid
part around, even though it will never match, for a couple of reasons:

- Serialization needs to include them
- For nesting, we care if a `&` appeared anywhere in the selector, even
  in an invalid part.

So this patch introduces an `Invalid` simple selector type, which simply
holds its original ComponentValues. We search through these looking for
`&`, and we dump them out directly when asked to serialize.
This commit is contained in:
Sam Atkins 2024-11-13 15:49:43 +00:00 committed by Andreas Kling
commit 5a1eb9e220
Notes: github-actions[bot] 2024-11-14 12:20:58 +00:00
8 changed files with 111 additions and 3 deletions

View file

@ -12,6 +12,7 @@
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibWeb/CSS/Keyword.h>
#include <LibWeb/CSS/Parser/ComponentValue.h>
#include <LibWeb/CSS/PseudoClass.h>
namespace Web::CSS {
@ -92,6 +93,7 @@ public:
PseudoClass,
PseudoElement,
Nesting,
Invalid,
};
struct ANPlusBPattern {
@ -195,8 +197,12 @@ public:
CaseType case_type;
};
struct Invalid {
Vector<Parser::ComponentValue> component_values;
};
Type type;
Variant<Empty, Attribute, PseudoClassSelector, PseudoElement, Name, QualifiedName> value {};
Variant<Empty, Attribute, PseudoClassSelector, PseudoElement, Name, QualifiedName, Invalid> value {};
Attribute const& attribute() const { return value.get<Attribute>(); }
Attribute& attribute() { return value.get<Attribute>(); }