fix: preserve path and query casing in normalize_url (#2008) - #2161
Draft
aryansk wants to merge 1 commit into
Draft
fix: preserve path and query casing in normalize_url (#2008)#2161aryansk wants to merge 1 commit into
aryansk wants to merge 1 commit into
Conversation
normalize_url lowercased the entire URL, including the path and query, so any two URLs differing only in path or query casing produced the same unique key and case-distinct pages were silently deduplicated. Per RFC 3986 only the scheme and host are case-insensitive; yarl already lowercases those on parse, so the explicit `.lower()` is removed and path/query/ fragment casing is preserved. This is a breaking change for persisted unique keys (issue suggests landing in 2.0).
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.
Summary
Fixes #2008 —
normalize_urllowercased the entire URL, including the path and query, so any two URLs differing only in path or query casing produced the same unique key:https://example.com/Product/ABCandhttps://example.com/product/abc→ same keyhttps://example.com/?token=SeCrEtandhttps://example.com/?token=secret→ same keyPer RFC 3986 §6.2.2.1 only the scheme and host are case-insensitive — the path and query are case-sensitive. On sites with case-sensitive paths (base64/hashid identifiers, usernames), case-distinct pages were silently deduplicated with no log message or statistic revealing it.
Change
yarlalready lowercases the scheme and host on parse (verified empirically:URL('HTTP://Example.COM/Product/ABC?Token=SeCrEt')→http://example.com/Product/ABC?Token=SeCrEt). The fix removes the final.lower()on the constructed URL so path/query/fragment casing survives normalization, matching browser behavior. The docstring now states precisely which parts are case-folded.Breaking change note: this changes how default unique keys are computed — crawls that relied on case-insensitive dedup will now visit more pages, and keys stored in persisted queues won't match newly computed ones. Per the issue, this should land in a major (2.0) release with the change documented loudly.
Validation
HTTPS://EXAMPLE.COM/?KEY=VALUE→https://example.com/?KEY=VALUE), path/query/fragment case preserved, trailing-slash removal unaffected.tests/unit/_utils— 299 passed, ruff check + format clean.