Skip to content

Commit

Permalink
Enable UTS46 mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasa committed Oct 14, 2016
1 parent 110684e commit 8dd51d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def prepare_url(self, url, params):

# 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.')

Expand Down
13 changes: 12 additions & 1 deletion tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 8dd51d2

Please sign in to comment.