Skip to content
Myr

Fix encode host (#2886)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Fix requiring dot literal rather than any character in IPv4 * Add check to prevent future errors

authored by robinaly · committed by GitHub · parent 3ba5fe0 · Browse files · 2 files+7 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+7 added−1 removed

  • tests:+6 added−0 removed
  • other:+1 added−1 removed

2 files+7 added−1 removed

modified:httpx/_urlparse.py+1 added-1 removed
85 unmodified lines
868788# We use these simple regexs as a first pass before handing off to89# the stdlib 'ipaddress' module for IP address validation.90IPv4_STYLE_HOSTNAME = re.compile(r"^[0-9]+.[0-9]+.[0-9]+.[0-9]+$")90IPv4_STYLE_HOSTNAME = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$")91IPv6_STYLE_HOSTNAME = re.compile(r"^\[.*\]$")929394class ParseResult(typing.NamedTuple):
370 unmodified lines
modified:tests/test_urlparse.py+6 added
43 unmodified lines
44 url = httpx.URL("https://EXAMPLE.com/")45 assert url.host == "example.com"464748def test_urlparse_ipv4_like_host():49 """rare host names used to quality as IPv4"""50 url = httpx.URL("https://023b76x43144/")51 assert url.host == "023b76x43144"525354def test_urlparse_valid_ipv4():55 url = httpx.URL("https://1.2.3.4/")56 assert url.host == "1.2.3.4"57
228 unmodified lines