summaryrefslogtreecommitdiffstats
path: root/Lib/urllib/parse.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2019-04-30 12:03:02 (GMT)
committerGitHub <noreply@github.com>2019-04-30 12:03:02 (GMT)
commitd537ab0ff9767ef024f26246899728f0116b1ec3 (patch)
tree03f8dca564bd759d5087c62d01179a629fe7584a /Lib/urllib/parse.py
parentb84cb70880a0acfcbbaca7bcda405af08f94d269 (diff)
downloadcpython-d537ab0ff9767ef024f26246899728f0116b1ec3.zip
cpython-d537ab0ff9767ef024f26246899728f0116b1ec3.tar.gz
cpython-d537ab0ff9767ef024f26246899728f0116b1ec3.tar.bz2
bpo-36742: Fixes handling of pre-normalization characters in urlsplit() (GH-13017)
Diffstat (limited to 'Lib/urllib/parse.py')
-rw-r--r--Lib/urllib/parse.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
index fb518a9..dfba704 100644
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -402,13 +402,16 @@ def _checknetloc(netloc):
# looking for characters like \u2100 that expand to 'a/c'
# IDNA uses NFKC equivalence, so normalize for this check
import unicodedata
- netloc2 = unicodedata.normalize('NFKC', netloc)
- if netloc == netloc2:
+ n = netloc.rpartition('@')[2] # ignore anything to the left of '@'
+ n = n.replace(':', '') # ignore characters already included
+ n = n.replace('#', '') # but not the surrounding text
+ n = n.replace('?', '')
+ netloc2 = unicodedata.normalize('NFKC', n)
+ if n == netloc2:
return
- _, _, netloc = netloc.rpartition('@') # anything to the left of '@' is okay
for c in '/?#@:':
if c in netloc2:
- raise ValueError("netloc '" + netloc2 + "' contains invalid " +
+ raise ValueError("netloc '" + netloc + "' contains invalid " +
"characters under NFKC normalization")
def urlsplit(url, scheme='', allow_fragments=True):