FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Do not IDNA-encode IPv6 literal hosts in to_uri() (#188) by mvaught02 · Pull Request #189 · python-hyper/hyperlink · GitHub

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

Filter by extension

Filter by extension .ini  (1) .py  (3) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 10 additions & 5 deletions src/hyperlink/_url.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1667,11 +1667,16 @@ def to_uri(self):
new_path = _encode_path_parts(
self.path, has_scheme=bool(self.scheme), rooted=False, maximal=True
)
new_host = (
self.host
if not self.host
else idna_encode(self.host, uts46=True).decode("ascii")
)
family, host_text = parse_host(self.host)
if family is not None:
# IPv4 / IPv6 literal
new_host = host_text
else:
new_host = (
self.host
if not self.host
else idna_encode(self.host, uts46=True).decode("ascii")
)
return self.replace(
userinfo=new_userinfo,
host=new_host,
Expand Down
3 changes: 2 additions & 1 deletion src/hyperlink/test/test_hypothesis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
except ImportError:
from mock import patch # type: ignore[misc]

from hypothesis import given, settings
from hypothesis import given, settings, HealthCheck
from hypothesis.strategies import SearchStrategy, data

from idna import IDNAError, check_label, encode as idna_encode
Expand Down Expand Up @@ -174,6 +174,7 @@ def test_hostnames_ascii(self, hostname):
)

@given(hostnames(allow_leading_digit=False, allow_idn=False))
@settings(suppress_health_check=[HealthCheck.filter_too_much])
def test_hostnames_ascii_nolead(self, hostname):
# type: (Text) -> None
"""
Expand Down
5 changes: 5 additions & 0 deletions src/hyperlink/test/test_parse.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ def test_parse(self):

with self.assertRaises(UnicodeDecodeError):
purl3.fragment

def test_ipv6_literal_not_idna_encoded(self) -> None:

url = EncodedURL.from_text("http://[::1]:8080/path")
assert url.to_uri().to_text() == "http://[::1]:8080/path"
1 change: 1 addition & 0 deletions tox.ini
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ skip_install = True

deps =
black==21.7b0
click<8.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What's this bound about?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

When I ran this locally for tests I had to pin this back to get tests to work with older versions. This goes away when that other PR is merged.


setenv =
BLACK_LINT_ARGS=--check
Expand Down
Loading

Back | FazBrowse Home | New Git URL