Skip to content

Match attribute selector names ASCII case-insensitively - #332

Merged
orium merged 1 commit into
cloudflare:mainfrom
robobun:fix/uppercase-attribute-name-selector
Jul 29, 2026
Merged

Match attribute selector names ASCII case-insensitively#332
orium merged 1 commit into
cloudflare:mainfrom
robobun:fix/uppercase-attribute-name-selector

Conversation

@robobun

@robobun robobun commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #328.

[HREF] was accepted but silently matched nothing: Condition::from stored local_name (the selector as written) while AttributeMatcher::find compares against lowercased element attribute names. Use local_name_lower instead.

[HREF=x] threw NamespacedSelector: the selectors crate emits Component::AttributeOther for any attribute name that isn't already ASCII-lowercase (namespace.is_some() || !local_name_is_ascii_lowercase), and validate_component rejected every AttributeOther without checking whether a namespace is present. Accept it when namespace is None and lower it to the existing AttributeExists/AttributeComparisonExpr expressions using local_name_lower.

Selectors with an actual namespace ([*|foo]) are still rejected.

`[HREF]` was accepted but silently matched nothing because
`Condition::from` stored `local_name` (the selector as written)
instead of `local_name_lower`, while `AttributeMatcher::find`
compares against lowercased element attribute names.

`[HREF=x]` threw `NamespacedSelector` because the `selectors` crate
emits `Component::AttributeOther` for any attribute name that isn't
already ASCII-lowercase, and `validate_component` rejected every
`AttributeOther` without checking whether a namespace is actually
present.

Fixes cloudflare#328
@robobun
robobun force-pushed the fix/uppercase-attribute-name-selector branch from 66ed25b to a80e470 Compare July 27, 2026 06:55
@orium
orium merged commit cf6ae5c into cloudflare:main Jul 29, 2026
3 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.

Attribute selectors with an uppercase attribute name either throw or silently match nothing

2 participants