Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[selectors] selector list with invalid selector #14442

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions css/selectors/contains-invalid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html>
<head>
<title>CSS Selectors: selector list containing invalid selector</title>
<link rel="help" href="https://drafts.csswg.org/selectors-4/#grouping">
<meta name="assert" content="If a selector is invalid, the entire selector list is invalid.">
<meta name="assert" content="Pseudo-elements are not valid within :is :not :where.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
.a, .b, .c {
color: lime;
}

.a, :nonsense {
color: red;
}

/* Pseudo-elements cannot be represented by the matches-any pseudo-class; they are not valid within :is(). */
.b, :is(::before) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the edits for w3c/csswg-drafts#3264 (comment) haven't been done yet and the discussion is still ongoing, it's not entirely clear what should happen to :is() with a single invalid argument. I would expect that the new invalidation rules would mean that since ::before is not allowed in :is() it gets discarded, but that this merely cause that argument of :is() (in this case its only argument) to be discarded, and the :is() construct as a whole remains valid, even if it matches nothing. So the whole rule is not treated as a syntax error, .b matches, and the element turns red. Which makes the test wrong.

color: red;
}
.b, :not(::before) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of the same comment as https://github.com/web-platform-tests/wpt/pull/14442/files#r240427239, except that there's still ongoing discussion in that issue about how invalidation of :not() arguments should work. We should wait until the dust settles on that.

color: red;
}
.b, :where(::before) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

color: red;
}

.c:is(*, :nonsense) {
Copy link
Contributor

@frivoal frivoal Dec 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on w3c/csswg-drafts#3264 (comment), this one should actually match.

color: red;
}
.c:not(*, :nonsense) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's remaining discussion in w3c/csswg-drafts#3264 (comment) about what should happen to :not() with invalid arguments. As currently resolved, it should match (so the test would be wrong), but maybe we'll change that, so I would wait for the dust to settle before landing this PR, as this may or may not need fixing.

color: red;
}
.c:where(*, :nonsense) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for :is, based on w3c/csswg-drafts#3264 (comment), this one should match.

color: red;
}
</style>
</head>
<body>
<div id="a" class="a">
</div>
<div id="b" class="b">
</div>
<div id="c" class="c">
</div>
<script>
const lime = "rgb(0, 255, 0)";

test(() => {
assert_equals(getComputedStyle(a).color, lime);
}, "If a selector is invalid, the entire selector list is invalid.");

test(() => {
assert_equals(getComputedStyle(b).color, lime);
}, "Pseudo-elements are not valid within :is :not :where.");

test(() => {
assert_equals(getComputedStyle(c).color, lime);
}, "If a selector in :is :not :where is invalid, the entire selector is invalid.");
</script>
</body>
</html>