Skip to content

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

Open
NevanDeCoteau wants to merge 1 commit into
fb55:masterfrom
NevanDeCoteau:fix-empty-attribute-match-1910
Open

NevanDeCoteau wants to merge 1 commit into
fb55:masterfrom
NevanDeCoteau:fix-empty-attribute-match-1910

Conversation

@NevanDeCoteau

@NevanDeCoteau NevanDeCoteau commented Oct 13, 2026 •

Copy link
Copy Markdown

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 correctly match no elements. Existing selectors with non-empty values continue to work.

@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-10-13T18:52:25.444416Z 582097c PR opened
ℹ️ 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

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: b3e28bbf-95b3-4eae-9e0d-7c19d46b06d1
📥 Commits

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

📒 Files selected for processing: 2
  • src/attributes.ts
  • test/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.

📝 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.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 58209

The empty ~= selector now matches no elements, while non-empty whole-word matching remains covered. No actionable merge risk is identified.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preventing matches for empty ~= attribute values.
Linked Issues check Passed The PR satisfies issue #1910. src/attributes.ts now returns boolbase.falseFunc when the ~= value is empty or contains whitespace. Tests verify compilation to falseFunc, zero matches for the fo…
Out of Scope Changes check Passed The changes stay within issue #1910. The source change implements the empty-value rule, and the added tests cover the required regression and preserve existing whole-word behavior. No unrelated change…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ 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 checked the selector with care,
An empty value found no match there.
Whitespace still gets turned away,
While x finds three along the way.
Then off hopped the rabbit, pleased with the day.

Comment @coderabbitai help to get the list of available commands.

@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

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; empty ~= operands now match nothing, while nonempty matching remains unchanged.

Summary

Makes [a~=""] match nothing by returning boolbase.falseFunc before building the word-matching regex.

  • Empty ~= values match no elements.

No actionable issues found. Tests were inspected but not run.

Reviews (1) · Last reviewed commit: "fix: don't match anything for empty ~= v..." · Reviewed by Greptile

This branch has not been deployed

No deployments
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

1 participant