From a0cdc152735806a6fdb1f15dc8b83b2cf9b9cb5e Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sun, 26 Jul 2020 10:45:44 +0300 Subject: [PATCH] Fix #386: Convert host to lowercase on URL building --- CHANGES/386.feature | 1 + yarl/_url.py | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 CHANGES/386.feature diff --git a/CHANGES/386.feature b/CHANGES/386.feature new file mode 100644 index 000000000..a44021b7c --- /dev/null +++ b/CHANGES/386.feature @@ -0,0 +1 @@ +Convert host to lowercase on URL building. diff --git a/yarl/_url.py b/yarl/_url.py index 74d0dbd2a..563b53d2a 100644 --- a/yarl/_url.py +++ b/yarl/_url.py @@ -706,6 +706,7 @@ def _encode_host(cls, host): ip, sep, zone = host.partition("%") ip = ip_address(ip) except ValueError: + host = host.lower() # IDNA encoding is slow, # skip it for ASCII-only strings # Don't move the check into _idna_encode() helper @@ -729,6 +730,8 @@ def _encode_host(cls, host): ip, sep, zone = host.partition("%") ip = ip_address(ip) except ValueError: + host = host.lower() + for char in host: if char > "\x7f": break