summaryrefslogtreecommitdiffstats
path: root/Lib/nturl2path.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-04-23 17:28:05 (GMT)
committerGitHub <noreply@github.com>2021-04-23 17:28:05 (GMT)
commit04bcfe001cdf6290cb78fa4884002e5301e14c93 (patch)
tree37025a5f9feead04f9b52e3db638b6341a8a40eb /Lib/nturl2path.py
parente259a77f21bdfc7d4195913b379cbd6daee45d0d (diff)
downloadcpython-04bcfe001cdf6290cb78fa4884002e5301e14c93.zip
cpython-04bcfe001cdf6290cb78fa4884002e5301e14c93.tar.gz
cpython-04bcfe001cdf6290cb78fa4884002e5301e14c93.tar.bz2
bpo-43607: Fix urllib handling of Windows paths with \\?\ prefix (GH-25539)
(cherry picked from commit 3513d55a617012002c3f82dbf3cec7ec1abd7090) Co-authored-by: Steve Dower <steve.dower@python.org>
Diffstat (limited to 'Lib/nturl2path.py')
-rw-r--r--Lib/nturl2path.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/nturl2path.py b/Lib/nturl2path.py
index 853e660..61852af 100644
--- a/Lib/nturl2path.py
+++ b/Lib/nturl2path.py
@@ -50,6 +50,14 @@ def pathname2url(p):
# becomes
# ///C:/foo/bar/spam.foo
import urllib.parse
+ # First, clean up some special forms. We are going to sacrifice
+ # the additional information anyway
+ if p[:4] == '\\\\?\\':
+ p = p[4:]
+ if p[:4].upper() == 'UNC\\':
+ p = '\\' + p[4:]
+ elif p[1:2] != ':':
+ raise OSError('Bad path: ' + p)
if not ':' in p:
# No drive specifier, just convert slashes and quote the name
if p[:2] == '\\\\':
@@ -59,7 +67,7 @@ def pathname2url(p):
p = '\\\\' + p
components = p.split('\\')
return urllib.parse.quote('/'.join(components))
- comp = p.split(':')
+ comp = p.split(':', maxsplit=2)
if len(comp) != 2 or len(comp[0]) > 1:
error = 'Bad path: ' + p
raise OSError(error)