Repository navigation
fix: don't match anything for empty ~= attribute value - #1916
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
[Low impact] The PR appears safe to merge.
|
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>
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.
Summary by CodeRabbit
~=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.