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
3 changes: 2 additions & 1 deletion docs/source/release-notes/unreleased.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2.x.y - 202z-aa-bb
------------------

- *Add Items here*
- Fix ``ParseResultBytes.unsplit()`` raising ``AttributeError`` for
references without an authority, such as ``/a`` or ``mailto:x``.

.. links below here
7 changes: 5 additions & 2 deletions src/rfc3986/parseresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,12 @@ def from_string(
)

@property
def authority(self) -> bytes:
def authority(self) -> t.Optional[bytes]:
"""Return the normalized authority."""
return self.reference.authority.encode(self.encoding)
authority = self.reference.authority
if authority is None:
return None
return authority.encode(self.encoding)

def copy_with(
self,
Expand Down
12 changes: 12 additions & 0 deletions tests/test_parseresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ def test_unsplit(self):
idna_encoded = SNOWMAN_IDNA_HOST.encode("utf-8") + b"/path"
assert uri.unsplit(use_idna=True) == idna_encoded

@pytest.mark.parametrize(
"reference", [b"/a", b"a", b"mailto:x", b"?q", b"#f"]
)
def test_unsplit_reference_without_authority(self, reference):
uri = pr.ParseResultBytes.from_string(reference)
assert uri.authority is None
assert uri.unsplit() == reference
assert (
pr.ParseResult.from_string(reference.decode()).unsplit()
== reference.decode()
)

def test_eager_normalization_from_string(self):
uri = pr.ParseResultBytes.from_string(
b"http://" + SNOWMAN + b".com/path",
Expand Down