Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/rfc3986/_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,14 @@ def unsplit(self) -> str:
if self.authority:
result_list.extend(["//", self.authority])
if self.path:
result_list.append(self.path)
path = self.path
# A path that starts with "//" is a network-path reference
# (RFC 3986 §4.2). Without an authority, reconstituting it
# as-is would produce "scheme://host" and the next parse
# would steal the first segment as the authority.
if path.startswith("//") and not self.authority:
path = "/." + path
result_list.append(path)
if self.query is not None:
result_list.extend(["?", self.query])
if self.fragment is not None:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ def test_scheme_and_path_uri_unsplits(self, scheme_and_path_uri):
uri = self.test_class.from_string(scheme_and_path_uri)
assert uri.unsplit() == scheme_and_path_uri

def test_normalize_does_not_invent_an_authority(self):
# scheme:/..///bar has no authority. Removing dot-segments leaves
# path "//bar"; unsplitting that as-is becomes scheme://bar.
uri = self.test_class.from_string("scheme:/..///bar")
assert uri.authority is None
normalized = uri.normalize()
assert normalized.authority is None
rebuilt = self.test_class.from_string(normalized.unsplit())
assert rebuilt.authority is None
assert rebuilt.scheme == "scheme"


class TestURIReferenceComparesToStrings:
def test_basic_uri(self, basic_uri):
Expand Down