You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
URL.host returns Punycode instead of Unicode for some URLs #3332
The URL.host property does not decode IDNA hostnames into Unicode, which contradicts the specification. According to the httpx documentation, the host should always be returned as a string, normalized to lowercase, with IDNA hosts decoded into Unicode.
Step to reproduce
fromurllib.parseimporturlparsefromhttpximportURLtest_url="https://www.égalité-femmes-hommes.gouv.fr"print(URL(test_url).host) # Expected: "www.égalité-femmes-hommes.gouv.fr", but returns: "www.xn--galit-femmes-hommes-9ybf.gouv.fr"print(urlparse(test_url).hostname) # returns: "www.égalité-femmes-hommes.gouv.fr". idna.decode() also returns this.
The use of startswith("xn--") checks only for Punycode-encoded hosts that begin with this prefix. However, it should handle cases where IDNA encoding is used more comprehensively.
Replacing host.startswith("xn--") with something like if "xn--" in host might handle a broader set of cases?
changed the title [-] URL.host returns Punycode instead of Unicode for some URLS[/-][+] URL.host returns Punycode instead of Unicode for some URLs[/+]on Oct 4, 2024
Activity
[-] URL.host returns Punycode instead of Unicode for some URLS[/-][+] URL.host returns Punycode instead of Unicode for some URLs[/+]