Skip to content

Commit

Permalink
fix(url): canonicalize_url('http://您好.中国:80/') failed
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwei90 committed Sep 14, 2017
1 parent 34435d0 commit 749734c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion w3lib/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,15 @@ def _safe_ParseResult(parts, encoding='utf8', path_encoding='utf8'):
# IDNA encoding can fail for too long labels (>63 characters)
# or missing labels (e.g. http://.example.com)
try:
netloc = parts.netloc.encode('idna')
idx = parts.netloc.rfind(u':')
if idx != -1:
hostname = parts.netloc[:idx]
portpart = parts.netloc[idx:]
else:
hostname = parts.netloc
portpart = u''
hostname = to_unicode(hostname.encode('idna'))
netloc = hostname + portpart
except UnicodeError:
netloc = parts.netloc

Expand Down

0 comments on commit 749734c

Please sign in to comment.