Fix double '//' on URLs with empty authority and '//'-prefixed path (#185) - #197
Open
deepakganesh78 wants to merge 1 commit into
Open
Conversation
…xed path
furl('////path').url returned '//////path' instead of '////path' on
Python 3.9+.
Root cause: In FurlBase.tostr(), when scheme is None and netloc is '',
furl unconditionally prepended '//' to denote the empty authority.
Since Python 3.9, urllib.parse.urlunsplit() already prepends '//' to a
result whose path begins with '//' (per RFC 3986 section 3.3, to keep
the path from being misparsed as an authority). furl then added a
second '//', doubling the leading slashes.
Fix: only prepend '//' when urlunsplit()'s output doesn't already start
with it. This restores correct round-tripping for '////path', '///',
etc. while leaving all other cases unchanged.
Adds regression assertions to test_odd_urls (the existing '////path'
assertion there was already failing on 3.9+).
Fixes gruns#185
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.
Fixes #185.
Root cause
furl('////path').urlreturned'//////path'instead of'////path'on Python 3.9+.In
FurlBase.tostr(), whenscheme is Noneandnetloc == '', furl unconditionally prepended'//'to denote the empty authority:Since Python 3.9,
urllib.parse.urlunsplit()already prepends'//'to a result whose path begins with'//'(per RFC 3986 §3.3, to prevent the path from being misparsed as an authority). furl then added a second'//', doubling the leading slashes. This is the stdlib change referenced in the issue and is why the existingtest_odd_urlsassertion (furl('////path').url == '////path') began failing on 3.9+.Fix
Only prepend
'//'whenurlunsplit()'s output doesn't already start with it. All other cases are unchanged;'////path','///','///x','//','////'now all round-trip correctly.Tests
Extended
test_odd_urlswith round-trip assertions for'////path','//','///','///x','////'. Added a changelog entry.Full suite: 75 passed, 2 failed. The 2 failures (
test_hosts,test_netloc) are pre-existing and unrelated — they concern IPv6 validation under neweripaddress(issue #182 / #176) and fail identically on a clean checkout without this change.