Skip to content

Commit 2ca2afc

Browse files
committed
Fix ParseResultBytes when we have a valid IRI
Closes #57
1 parent 9186920 commit 2ca2afc

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

docs/source/release-notes/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ here with the newest releases first.
1010

1111
.. toctree::
1212

13+
unreleased
1314
1.4.0
1415
1.3.2
1516
1.3.1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
1.x.y - 202z-aa-bb
2+
------------------
3+
4+
- Fix bug where a valid IRI is mishandled by ``urlparse`` and
5+
``ParseResultBytes``.
6+
7+
See also `GitHub #57`_
8+
9+
10+
.. links
11+
12+
.. _GitHub #57:
13+
https://github.com/python-hyper/rfc3986/issues/57

src/rfc3986/parseresult.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def _generate_authority(self, attributes):
4343
compat.to_str(host, self.encoding),
4444
port)
4545
)
46+
if isinstance(self.authority, bytes):
47+
return self.authority.decode('utf-8')
4648
return self.authority
4749

4850
def geturl(self):

tests/test_unicode_support.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ def test_urlparse_a_unicode_hostname_with_auth():
4949
assert parsed.userinfo == 'userinfo'
5050

5151

52+
def test_urlparse_idna_encoding_with_geturl():
53+
"""https://github.com/python-hyper/rfc3986/issues/57"""
54+
parsed = urlparse("https://i❤.ws")
55+
encoded = parsed.encode('idna')
56+
assert encoded.encoding == 'idna'
57+
assert encoded.geturl() == b'https://xn--i-7iq.ws'
58+
59+
5260
def test_urlparse_an_invalid_authority_parses_port():
5361
url = 'http://foo:b@r@[::1]:80/get'
5462
parsed = urlparse(url)

0 commit comments

Comments
 (0)