Return domain name early if ASCII only

This commit is contained in:
Jonas Mueller 2023-10-23 09:38:00 +02:00 committed by HoneyryderChuck
parent 61ce888e47
commit 554b5a663c

View File

@ -61,8 +61,12 @@ module HTTPX
# Normalizes a _domain_ using the Punycode algorithm as necessary.
# The result will be a downcased, ASCII-only string.
def normalize(domain)
domain = domain.chomp(".").unicode_normalize(:nfc) unless domain.ascii_only?
Punycode.encode_hostname(domain).downcase
unless domain.ascii_only?
domain = domain.chomp(".").unicode_normalize(:nfc)
domain = Punycode.encode_hostname(domain)
end
domain.downcase
end
end