Fix: In furl.py's tostr() (~line 1826), url =... - #199
Open
M001N wants to merge 1 commit into
Open
Conversation
urllib.parse.urlunsplit() on modern Python already disambiguates an
empty netloc from a path starting with '//' by inserting extra
slashes itself. furl's manual '//' + url prepend, added to compensate
for older urlunsplit behavior, was double-adding these slashes,
turning furl('////path').url into '//////path' instead of '////path'.
Guard the prepend so it only fires if urlunsplit's output doesn't
already start with '//', making the code correct across urlunsplit
versions/behaviors.
Fixes gruns#176
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
Guarded the manual prepend with
if not url.startswith('//')before adding '//' + url, inside the existingif self.scheme is Nonebranch. This detects at runtime whether urlunsplit already disambiguated the netloc/path boundary, so the fix is correct regardless of the exact stdlib version behavior (no need for a sys.version_info split).Problem
gruns/furl issue reference: #176
Root Cause
In furl.py's tostr() (~line 1826), url = urllib.parse.urlunsplit((scheme, netloc, path, query, fragment)) is called first. On modern Python (verified on 3.14.3 here, and true generally since Python 3.9+), urlunsplit(('', '', '//path', '', '')) already returns '////path' by itself to disambiguate an empty netloc from a path starting with '//'. The subsequent unconditional
if self.netloc == '' and self.scheme is None: url = '//' + urlwas written to compensate for an older urlunsplit that did NOT self-disambiguate, so on current Python it double-adds the slashes, producing '//////path'.Testing
PASS - test_odd_urls passes; furl('////path').url now returns '////path'. Manually spot-checked furl('http://host/path').url, furl('path').url, and furl('//host/path').url — all unchanged/correct, no regression.
Related Issue
#176