Repository navigation
Decode CSS escapes in a single pass - #203
Merged
Merged
Conversation
unescape_ident() and the string tokenizer decoded escapes with several re.sub() passes, so each pass rescanned the output of the previous one: an escaped backslash followed by hex digits (\\31) was decoded again as a unicode escape, and a backslash produced by \5c started a new simple escape. Decode every escape in one left-to-right pass instead.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #203 +/- ##
=======================================
Coverage 99.79% 99.79%
=======================================
Files 3 3
Lines 987 987
Branches 161 162 +1
=======================================
Hits 985 985
Misses 1 1
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
AdrianAtZyte
approved these changes
Oct 16, 2026
wRAR
approved these changes
Oct 16, 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.
CSS escapes are decoded more than once
unescape_ident()and the string branch oftokenize()decode escapes in separatere.sub()passes (unicode escapes, then simple escapes, plus escaped newlines first for strings). Each pass rescans what the previous one produced, so escape boundaries are lost:CSS Syntax §4.3.7 consumes each escape exactly once, left to right, so
\\is a literal backslash and the result of\5cis never read as the start of another escape. Here a selector can end up matching a different value or element name than the one it spells, which is the usual double-decoding problem for anything that inspects or builds selectors before translating them. Decoding every escape with one combined pattern in a single pass fixes both the identifier and the string path; valid input without a backslash next to an escape is unaffected and the existing tests pass unchanged.