You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. I think this would be a good fit for my first open-source contribution. I’m new to css-select and its codebase, but I’d like to try this issue if it’s still available.
So ~=/^=/$=/*= with an empty value never match, while |= keeps dash-list semantics.
Source.start (^=), end ($=), and any (*=) all early-return boolbase.falseFunc on empty values — but element (~=) only rejects whitespace-containing values (if (whitespaceRe.test(value))) and has no empty check. With value === "", its regex becomes (?:^|\s)(?:$|\s), which matches "", " x", "x ", and even "x y" (whitespace in the middle satisfies both anchors) — hence 4/4. hyphen (|=) is already correct via its length === 0 path.
The fix is one line — extend that guard to if (value === "" || whitespaceRe.test(value)), mirroring the three siblings.
Amusing footnote: I hit the mirror-image gap in what I use (@dooboostore/dom-parser) — the empty guard there covered ^=/$=/*= but was missing ~= (''.split(/\s+/) contains ''), so [a~=""] matched 3/4. Same one-line shape, and I verified 0/3/2/0/0/1 against Chromium on my setup.
Activity
NevanDeCoteau commentedon Oct 13, 2026
Hi. I think this would be a good fit for my first open-source contribution. I’m new to css-select and its codebase, but I’d like to try this issue if it’s still available.
visualkhh commentedon Oct 31, 2026
Ran into this class and pinned the exact line — the gap is visible by comparing the four sibling rules in
src/attributes.ts.Browser (Chromium, full empty-value matrix). On
<i a="">,<i a=" x">,<i a="x">,<i a="-x">:[a~=""]→0,[a|=""]→2(a=""anda="-x"),[a^=""]→0,[a$=""]→0,[a*=""]→0[a~="x"]→3,[a~="y"]→1,[a=""]→1,[a]→4So
~=/^=/$=/*=with an empty value never match, while|=keeps dash-list semantics.Source.
start(^=),end($=), andany(*=) all early-returnboolbase.falseFuncon empty values — butelement(~=) only rejects whitespace-containing values (if (whitespaceRe.test(value))) and has no empty check. Withvalue === "", its regex becomes(?:^|\s)(?:$|\s), which matches""," x","x ", and even"x y"(whitespace in the middle satisfies both anchors) — hence 4/4.hyphen(|=) is already correct via itslength === 0path.The fix is one line — extend that guard to
if (value === "" || whitespaceRe.test(value)), mirroring the three siblings.Amusing footnote: I hit the mirror-image gap in what I use (@dooboostore/dom-parser) — the empty guard there covered
^=/$=/*=but was missing~=(''.split(/\s+/)contains''), so[a~=""]matched 3/4. Same one-line shape, and I verified 0/3/2/0/0/1 against Chromium on my setup.fix: don't match anything for empty ~= attribute value (fb55#1916)