From 4f2a250c7ed6923e805b9e583c752a1a6571b8ef Mon Sep 17 00:00:00 2001 From: robinaly Date: Tue, 10 Oct 2023 10:42:52 +0200 Subject: [PATCH 1/2] Fix requiring dot literal rather than any character in IPv4 --- httpx/_urlparse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpx/_urlparse.py b/httpx/_urlparse.py index e1ba8dcdb7..8e060424e8 100644 --- a/httpx/_urlparse.py +++ b/httpx/_urlparse.py @@ -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"^\[.*\]$") From 3d3f4d4ebd146b31084efac56e079d9dc3dc3c08 Mon Sep 17 00:00:00 2001 From: robinaly Date: Tue, 10 Oct 2023 10:43:06 +0200 Subject: [PATCH 2/2] Add check to prevent future errors --- tests/test_urlparse.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_urlparse.py b/tests/test_urlparse.py index 3ae9b04ce6..b03291b44f 100644 --- a/tests/test_urlparse.py +++ b/tests/test_urlparse.py @@ -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"