Repository navigation
Use ASCII case folding for :lang() and attribute values - #201
Merged
Merged
Conversation
The document side of the :lang() comparison only folds A-Z through translate(), but the argument was folded with str.lower(), which maps U+212A (KELVIN SIGN) to "k" and U+0130 to "i" + U+0307. A :lang() argument containing U+212A therefore matched lang="K" while missing an actual U+212A language tag. Language-range matching is ASCII case-insensitive (RFC 4647), so fold the argument with ascii_lower(), and do the same for attribute values under the lower_case_attribute_values extension point, completing the name folding from scrapy#200.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #201 +/- ##
=======================================
Coverage 99.79% 99.79%
=======================================
Files 3 3
Lines 987 987
Branches 161 161
=======================================
Hits 985 985
Misses 1 1
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
wRAR
approved these changes
Oct 14, 2026
AdrianAtZyte
approved these changes
Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#200 moved element and attribute names to ASCII case folding, but two translation sites still fold the selector side of a comparison with full Unicode
str.lower()while the document side only folds A-Z: the:lang()argument inHTMLTranslator.xpath_lang_function(), and attribute values under thelower_case_attribute_valuesextension point.str.lower()maps exactly two non-ASCII code points into ASCII (U+212A KELVIN SIGN to "k", U+0130 to "i" plus U+0307), so a:lang()argument containing U+212A compiles tostarts-with(..., 'k-')and matcheslang="K"orlang="k", while an element whose lang is actually U+212A is missed:Language-range matching is ASCII case-insensitive (RFC 4647 section 3.3.1, and the HTML specification's definition of
:lang), so the argument must be folded the same way as thetranslate()already emitted for the@langside. Same reasoning for attribute values: that knob's contract is that the document parser lower-cased the values, an ASCII transformation.