Skip to content

Use ASCII case folding for case-insensitive attribute selectors - #37

Closed
jwalith4418-Mj wants to merge 1 commit into
Kozea:mainfrom
jwalith4418-Mj:fix/ascii-attribute-case-folding
Closed

jwalith4418-Mj wants to merge 1 commit into
Kozea:mainfrom
jwalith4418-Mj:fix/ascii-attribute-case-folding

Conversation

@jwalith4418-Mj

Copy link
Copy Markdown

Case-insensitive attribute selectors currently apply Python's Unicode .lower() to both operands. Consequently, [data-value="ÉA" i] incorrectly matches an attribute containing éa, and [data-value="k" i] matches the Kelvin sign K.

Selectors Level 4, section 6.3 restricts the i flag to ASCII case-insensitive matching, independently of the document language. Use the existing webencodings.ascii_lower helper for the selector constant and the generated attribute-value expression. That helper is already imported and available to compiled selectors. ASCII case differences still match; non-ASCII characters retain their identity.

The regression cases exercise all six attribute-value operators in both HTML and XML, distinguish accented uppercase/lowercase values, cover Unicode characters whose lowercasing introduces ASCII characters, and retain unflagged/s/S and i/I ASCII controls.

Validation:

  • Before the compiler change: 18 regressions fail, 10 controls pass.
  • After the change: all 28 focused cases pass.
  • Full Windows CPython 3.14.3 suite: 475 passed, 9 xfailed, 88% overall coverage. Coverage emits one configuration warning because --source takes precedence over the project's include setting.
  • python -m ruff check, Sphinx HTML, wheel/sdist and git diff --check: passed.
  • A separate Linux CPython 3.12 environment installed the wheel and passed public-API checks across all six operators and both document wrappers; the installed import path was verified.

The full CI interpreter/platform matrix was not run locally. This was found during source inspection and reproduced through the public API. OpenAI Codex assisted with investigation, implementation, validation and this description.

Apply the existing ascii_lower helper to both operands of i-flag comparisons, as required by Selectors Level 4. Cover all six operators, HTML/XML, non-ASCII-to-ASCII folds and explicit/default case controls.

AI-assisted investigation, implementation and validation using OpenAI Codex.
@grewn0uille

Copy link
Copy Markdown
Member

Please follow the contribution guidelines.

@grewn0uille grewn0uille closed this Nov 6, 2026
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.

2 participants