Skip to content

Fix double '//' on URLs with empty authority and '//'-prefixed path (#185) - #197

Open
deepakganesh78 wants to merge 1 commit into
gruns:masterfrom
deepakganesh78:fix/issue185-empty-authority-double-slash
Open

Fix double '//' on URLs with empty authority and '//'-prefixed path (#185)#197
deepakganesh78 wants to merge 1 commit into
gruns:masterfrom
deepakganesh78:fix/issue185-empty-authority-double-slash

Conversation

@deepakganesh78

Copy link
Copy Markdown

Fixes #185.

Root cause

furl('////path').url returned '//////path' instead of '////path' on Python 3.9+.

In FurlBase.tostr(), when scheme is None and netloc == '', furl unconditionally prepended '//' to denote the empty authority:

if self.netloc == '':
    if self.scheme is None:
        url = '//' + url

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 existing test_odd_urls assertion (furl('////path').url == '////path') began failing on 3.9+.

Fix

Only prepend '//' when urlunsplit()'s output doesn't already start with it. All other cases are unchanged; '////path', '///', '///x', '//', '////' now all round-trip correctly.

Tests

Extended test_odd_urls with 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 newer ipaddress (issue #182 / #176) and fail identically on a clean checkout without this change.

…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
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.

test!: Path ////path causing failures

1 participant