Skip to content

Commit

Permalink
Bug 1864647 - Don't crash when finding nested relative selectors. r=d…
Browse files Browse the repository at this point in the history
…shin

For now, do the same as pseudo-elements, which is effectively to keep
them in the replaced selector but don't match them. Avoid crashing in
this case.

I filed w3c/csswg-drafts#9600 since this issue
isn't specific about :has(), and depending on the result of that
discussion, the "proper" solution might be different.

Differential Revision: https://phabricator.services.mozilla.com/D193663

UltraBlame original commit: 69bede2c30ec37c0a9b3b44879e28a5dd1c0b1c5
  • Loading branch information
marco-c committed Nov 21, 2023
1 parent 026e14b commit 79727e6
Show file tree
Hide file tree
Showing 4 changed files with 434 additions and 37 deletions.
185 changes: 168 additions & 17 deletions servo/components/selectors/matching.rs
Expand Up @@ -3465,6 +3465,170 @@ false
}
None
}
fn
match_relative_selectors
<
E
:
Element
>
(
selectors
:
&
[
RelativeSelector
<
E
:
:
Impl
>
]
element
:
&
E
context
:
&
mut
MatchingContext
<
E
:
:
Impl
>
rightmost
:
Rightmost
)
-
>
bool
{
if
context
.
relative_selector_anchor
(
)
.
is_some
(
)
{
/
/
FIXME
(
emilio
)
:
This
currently
can
happen
with
nesting
and
it
'
s
not
fully
/
/
correct
arguably
.
But
the
ideal
solution
isn
'
t
super
-
clear
either
.
For
now
/
/
cope
with
it
and
explicitly
reject
it
at
match
time
.
See
[
1
]
for
discussion
.
/
/
/
/
[
1
]
:
https
:
/
/
github
.
com
/
w3c
/
csswg
-
drafts
/
issues
/
9600
return
false
;
}
context
.
nest_for_relative_selector
(
element
.
opaque
(
)
|
context
|
{
do_match_relative_selectors
(
selectors
element
context
rightmost
)
}
)
}
/
/
/
Expand All @@ -3480,7 +3644,7 @@ relative
selectors
.
fn
matches_relative_selectors
do_match_relative_selectors
<
E
:
Expand Down Expand Up @@ -6806,30 +6970,17 @@ relative_selectors
)
=
>
context
.
shared
.
nest_for_relative_selector
(
element
.
opaque
(
)
|
context
|
{
matches_relative_selectors
match_relative_selectors
(
relative_selectors
element
context
.
shared
rightmost
)
}
)
Component
:
:
Expand Down
52 changes: 32 additions & 20 deletions servo/components/style/invalidation/element/invalidation_map.rs
Expand Up @@ -7363,17 +7363,23 @@ Impl
>
bool
{
unreachable
!
(
"
Nested
/
/
Ignore
nested
relative
selector
?
"
)
;
selectors
.
These
can
happen
as
a
result
of
nesting
.
true
}
fn
visit_simple_selector
Expand Down Expand Up @@ -8712,17 +8718,23 @@ Impl
>
bool
{
unreachable
!
(
"
Nested
/
/
Ignore
nested
relative
selector
?
"
)
;
selectors
.
These
can
happen
as
a
result
of
nesting
.
true
}
fn
visit_simple_selector
Expand Down
46 changes: 46 additions & 0 deletions testing/web-platform/tests/css/css-nesting/has-nesting-ref.html
@@ -0,0 +1,46 @@
<
!
doctype
html
>
<
title
>
Nested
has
shouldn
'
t
match
<
/
title
>
<
style
>
ul
{
background
:
green
}
<
/
style
>
<
ul
>
<
li
>
Bar
<
/
li
>
<
/
ul
>

0 comments on commit 79727e6

Please sign in to comment.