From 8dd51d22fc42abf98f8e75ff5722f4b0295015e5 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Fri, 14 Oct 2016 15:13:37 +0100 Subject: [PATCH] Enable UTS46 mode. --- requests/models.py | 2 +- tests/test_requests.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/requests/models.py b/requests/models.py index 82be7802..db9df865 100644 --- a/requests/models.py +++ b/requests/models.py @@ -364,7 +364,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): # Only want to apply IDNA to the hostname try: - host = idna.encode(host).decode('utf-8') + host = idna.encode(host, uts46=True).decode('utf-8') except (UnicodeError, idna.IDNAError): raise InvalidURL('URL has an invalid label.') diff --git a/tests/test_requests.py b/tests/test_requests.py index 96b3c9bf..f2d56b9e 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -1900,11 +1900,22 @@ class TestPreparingURLs(object): u'http://ジェーピーニック.jp'.encode('utf-8'), u'http://xn--hckqz9bzb1cyrb.jp/' ), - (u'http://straße.de/straße', u'http://xn--strae-oqa.de/stra%C3%9Fe'), + ( + u'http://straße.de/straße', + u'http://xn--strae-oqa.de/stra%C3%9Fe' + ), ( u'http://straße.de/straße'.encode('utf-8'), u'http://xn--strae-oqa.de/stra%C3%9Fe' ), + ( + u'http://Königsgäßchen.de/straße', + u'http://xn--knigsgchen-b4a3dun.de/stra%C3%9Fe' + ), + ( + u'http://Königsgäßchen.de/straße'.encode('utf-8'), + u'http://xn--knigsgchen-b4a3dun.de/stra%C3%9Fe' + ), ) ) def test_preparing_url(self, url, expected):