Skip to content

fix: don't match anything for empty ~= attribute value - #1916

Merged
fb55 merged 3 commits into
fb55:masterfrom
NevanDeCoteau:fix-empty-attribute-match-1910
Nov 6, 2026
Merged

fb55 merged 3 commits into
fb55:masterfrom
NevanDeCoteau:fix-empty-attribute-match-1910

Conversation

@NevanDeCoteau

@NevanDeCoteau NevanDeCoteau commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1910

Per the CSS spec, [a~=""] matches nothing. css-select matched elements with an empty value and values with leading, trailing or doubled spaces, because an empty value produced a regex that matches the empty string.

This change makes the ~= rule return falseFunc for an empty value, the same way it already does for values containing whitespace.

Tests added to test/attributes.ts:

[foo~=''] compiles to falseFunc
[a~=""] matches none of the four elements from the issue
[a~="x"] still matches whole words

I confirmed the new tests fail without the fix. The full test suite and lint pass locally.

View guided diff

Summary by CodeRabbit

  • Bug Fixes
    • Attribute selectors using ~= with an empty value now match no elements. Selectors using ~= with a non-empty value continue to match elements as expected, including cases where the value appears among an element’s whitespace-separated attribute values.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T01:56:01.803081Z 62353b7 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The ~= attribute selector now returns a non-matching function when its value is empty or contains whitespace. Tests cover the compiled matcher and DOM selection for empty and non-empty values.

Changes: Empty ~= Matching

Layer / File(s) Summary
Reject empty ~= values
src/attributes.ts, test/attributes.ts
The selector rejects empty values as well as values containing whitespace. Tests verify that an empty value matches no elements and that x matches three elements.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to 62353

Empty-value selectors should no longer match elements. No material merge risk was identified.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the fix for empty ~= attribute values.
Linked Issues check Passed [#1910] src/attributes.ts returns falseFunc for an empty ~= value. test/attributes.ts checks that the selector compiles to falseFunc. This covers all four reported attribute values. The DOM …
Out of Scope Changes check Passed [#1910] The change summary identifies only the attribute rule and its tests. Both support the issue. The incremental diff was unavailable, but the whole-PR summary establishes the reported scope.
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Full details: Linked Issues check

Explanation

[#1910] src/attributes.ts returns falseFunc for an empty ~= value. test/attributes.ts checks that the selector compiles to falseFunc. This covers all four reported attribute values. The DOM selection tests described in the summary are not present in the inspected head file.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the selector’s cue
Empty words now match nothing through
Whitespace still gets turned away
Three x results pass the test today
I hop through fields, then nibble hay

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 778de318-bfb6-445c-a3e5-fa124f13568e
Commits

Reviewing files that changed from the base of the PR and between 582097c and 62353b7.

Files selected for processing: 1

  • src/attributes.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

View guided diff | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Empty ~= attribute selectors now match nothing.

  • Empty ~= selectors match no elements.

Reviews (2) · Last reviewed commit: "refactor(attributes): shorten the empty ..." · Reviewed by Greptile

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`value` is always a string, so `!value` is the same check as
`value === ""`. The `selectAll` test runs the same early return as the
`[foo~='']` compile test, and the whole-word test passes on master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fb55
fb55 merged commit ca67a21 into fb55:master Nov 6, 2026
12 checks passed
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

Successfully merging this pull request may close these issues.

[a~=""] matches elements

2 participants