Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encode host #2886

Merged
merged 2 commits into from
Oct 10, 2023
Merged
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
2 changes: 1 addition & 1 deletion httpx/_urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

# We use these simple regexs as a first pass before handing off to
# the stdlib 'ipaddress' module for IP address validation.
IPv4_STYLE_HOSTNAME = re.compile(r"^[0-9]+.[0-9]+.[0-9]+.[0-9]+$")
IPv4_STYLE_HOSTNAME = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$")
IPv6_STYLE_HOSTNAME = re.compile(r"^\[.*\]$")


Expand Down
6 changes: 6 additions & 0 deletions tests/test_urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def test_urlparse_normalized_host():
assert url.host == "example.com"


def test_urlparse_ipv4_like_host():
"""rare host names used to quality as IPv4"""
url = httpx.URL("https://023b76x43144/")
assert url.host == "023b76x43144"


def test_urlparse_valid_ipv4():
url = httpx.URL("https://1.2.3.4/")
assert url.host == "1.2.3.4"
Expand Down