Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Sep 26, 2024
1 parent 918da42 commit fdd12b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/test_url_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,28 @@ def test_schemes_that_require_host(scheme: str) -> None:
)
with pytest.raises(ValueError, match=expect):
URL(f"{scheme}://:1")


@pytest.mark.parametrize(
("url", "hostname", "hostname_without_brackets"),
[
("http://[::1]", "[::1]", "::1"),
("http://[::1]:8080", "[::1]", "::1"),
("http://127.0.0.1:8080", "127.0.0.1", "127.0.0.1"),
(
"http://xn--jxagkqfkduily1i.eu",
"xn--jxagkqfkduily1i.eu",
"xn--jxagkqfkduily1i.eu",
),
],
)
def test_ipv6_url_round_trips(
url: str, hostname: str, hostname_without_brackets: str
) -> None:
"""Verify that IPv6 URLs round-trip correctly."""
parsed = URL(url)
assert parsed._val.hostname == hostname_without_brackets
assert parsed.raw_host == hostname_without_brackets
assert parsed.host_subcomponent == hostname
assert str(parsed) == url
assert str(URL(str(parsed))) == url
2 changes: 1 addition & 1 deletion yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def __str__(self) -> str:
netloc=self._make_netloc(
self.raw_user,
self.raw_password,
self.raw_host,
self.host_subcomponent,
port,
encode_host=False,
)
Expand Down

0 comments on commit fdd12b9

Please sign in to comment.