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

Tests for :empty selector are out of spec #50327

Open
KyNorthstar opened this issue Jan 28, 2025 · 0 comments
Open

Tests for :empty selector are out of spec #50327

KyNorthstar opened this issue Jan 28, 2025 · 0 comments

Comments

@KyNorthstar
Copy link

The tests for the :empty pseudo-class test the behavior of :empty in selectors level 3, but that behavior is deprecated and was replaced in selectors level 4.

The current spec requires that :empty match any element with nothing inside it, and also any element containing only whitespace. Of course, comments are removed before checking for this whitespace-ignoring emptiness.

However, the tests for the :empty pseudo-class expect that :empty doesn't match elements containing only whitespace (comment optional).

This test should be updated to test against the current spec.

Here's the current spec for :empty, for convenience:

14.2. :empty pseudo-class

The :empty pseudo-class represents an element that has no children except, optionally, document white space characters. In terms of the document tree, only element nodes and content nodes (such as [DOM] text nodes, and entity references) whose data has a non-zero length must be considered as affecting emptiness; comments, processing instructions, and other nodes must not affect whether an element is considered empty or not.

EXAMPLE 48

Examples: p:empty is a valid representation of the <p> elements in the following HTML fragment:

<p></p>
<p>
<p> </p>
<p> <!-- comment --></p>

div:empty is not a valid representation of the <div> elements in the following fragment:

<div>text</div>
<div><p></p></div>
<div>&nbsp;</div>
<div><p>bla</p></div>
<div>this is not <p>:empty</p></div>

NOTE: In Level 2 and Level 3 of Selectors, :empty did not match elements that contained only white space. This was changed so that that—​given white space is largely collapsible in HTML and is therefore used for source code formatting, and especially because elements with omitted end tags are likely to absorb such white space into their DOM text contents—​elements which authors perceive of as empty can be selected by this selector, as they expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant