Skip to content
Myr

Update IDNA encoding to 2008 spec (#161)

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

* Update IDNA encoding to 2008 spec * Add Unicode IDNA Compatibility Processing * Parametrize idna test * Use rfc3986 iri_reference for IDNA names * Add test for IRI object * Remove test_iri as this interface has been removed

authored by Stephen Brown II · committed by Tom Christie · parent 66754ad · Browse files · 2 files+57 added−11 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+57 added−11 removed

  • tests:+56 added−4 removed
  • other:+1 added−7 removed

2 files+57 added−11 removed

modified:httpx/models.py+1 added-7 removed
87 unmodified lines
88 allow_relative: bool = False,89 params: QueryParamTypes = None,90 ) -> None:91 if isinstance(url, str):92 self._uri_reference = rfc3986.api.uri_reference(url)92 self._uri_reference = rfc3986.api.iri_reference(url).encode()93 else:94 self._uri_reference = url._uri_reference9596 # Handle IDNA domain names.97 if self._uri_reference.authority:98 idna_authority = self._uri_reference.authority.encode("idna").decode("ascii")99 if idna_authority != self._uri_reference.authority:100 self._uri_reference = self._uri_reference.copy_with(authority=idna_authority)10196 # Normalize scheme and domain name.97 if self.is_absolute_url:98 self._uri_reference = self._uri_reference.normalize()99
1080 unmodified lines
modified:tests/models/test_url.py+56 added-4 removed
1import pytest2import rfc398634from httpx import URL5from httpx.exceptions import InvalidURL677def test_idna_url():8 url = URL("http://中国.icom.museum:80/")9 assert url == URL("http://xn--fiqs8s.icom.museum:80/")10 assert url.host == "xn--fiqs8s.icom.museum"8@pytest.mark.parametrize(9 "given,idna,host,scheme,port",10 [11 (12 "http://中国.icom.museum:80/",13 "http://xn--fiqs8s.icom.museum:80/",14 "xn--fiqs8s.icom.museum",15 "http",16 80,17 ),18 (19 "http://Königsgäßchen.de",20 "http://xn--knigsgchen-b4a3dun.de",21 "xn--knigsgchen-b4a3dun.de",22 "http",23 80,24 ),25 ("https://faß.de", "https://xn--fa-hia.de", "xn--fa-hia.de", "https", 443),26 (27 "https://βόλος.com:443",28 "https://xn--nxasmm1c.com:443",29 "xn--nxasmm1c.com",30 "https",31 443,32 ),33 (34 "http://ශ්‍රී.com:444",35 "http://xn--10cl1a0b660p.com:444",36 "xn--10cl1a0b660p.com",37 "http",38 444,39 ),40 (41 "https://نامه‌ای.com:4433",42 "https://xn--mgba3gch31f060k.com:4433",43 "xn--mgba3gch31f060k.com",44 "https",45 4433,46 ),47 ],48 ids=[49 "http_with_port",50 "unicode_tr46_compat",51 "https_without_port",52 "https_with_port",53 "http_with_custom_port",54 "https_with_custom_port",55 ],56)57def test_idna_url(given, idna, host, scheme, port):58 url = URL(given)59 assert url == URL(idna)60 assert url.host == host61 assert url.scheme == scheme62 assert url.port == port636465def test_url():66 url = URL("https://example.org:123/path/to/somewhere?abc=123#anchor")
120 unmodified lines