Skip to content

Fix: In furl.py's tostr() (~line 1826), url =... - #199

Open
M001N wants to merge 1 commit into
gruns:masterfrom
M001N:oss-engine/5f4ce7c3-a47bc5f6
Open

Fix: In furl.py's tostr() (~line 1826), url =...#199
M001N wants to merge 1 commit into
gruns:masterfrom
M001N:oss-engine/5f4ce7c3-a47bc5f6

Conversation

@M001N

@M001N M001N commented Aug 10, 2026

Copy link
Copy Markdown

Summary

Guarded the manual prepend with if not url.startswith('//') before adding '//' + url, inside the existing if self.scheme is None branch. 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 = '//' + url was 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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant