Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ export const attributeRules: Record<
element(next, data, options) {
const { adapter } = options;
const { name, value } = data;
if (whitespaceRe.test(value)) {
/*
* An empty value (or one containing whitespace, which can never be a
* single token) matches nothing — same as `^=`/`$=`/`*=` with an empty
* value. See https://www.w3.org/TR/selectors-4/#attribute-representation
*/
if (value === "" || whitespaceRe.test(value)) {
return boolbase.falseFunc;
}

Expand Down
6 changes: 6 additions & 0 deletions test/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ describe("Attributes", () => {
);
});

it("should for ~= with an empty value", () => {
expect(CSSselect._compileUnsafe("[foo~='']")).toBe(
boolbase.falseFunc,
);
});
Comment on lines +94 to +98

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Consider adding a runtime DOM matching test for completeness.

The compilation test correctly verifies that [foo~=''] returns boolbase.falseFunc. However, consider adding a runtime test that verifies the selector returns no matches against actual DOM elements, similar to the case-insensitive tests in lines 78-84.

🧪 Suggested additional runtime test

Add this test case in the "no matches" describe block after line 98:

it("should not match elements for ~= with an empty value", () => {
    const matches = CSSselect.selectAll("[data-foo~='']", dom);
    expect(matches).toHaveLength(0);
});

This provides end-to-end verification that the selector behavior matches expectations against actual DOM.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/attributes.ts` around lines 94 - 98, Add a runtime DOM test verifying
that the selector [foo~=''] yields no matches: in the "no matches" describe
block (after the existing compilation test using CSSselect._compileUnsafe and
boolbase.falseFunc) add a test that calls CSSselect.selectAll("[data-foo~='']",
dom) and expects an empty result (length 0) to confirm end-to-end behavior;
reference the existing dom fixture and use the same test structure as the
case-insensitive tests for consistency.


it("should for $=", () => {
expect(CSSselect._compileUnsafe("[foo$='']")).toBe(
boolbase.falseFunc,
Expand Down