mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-43607: Fix urllib handling of Windows paths with \\?\ prefix (GH-25539)
(cherry picked from commit 3513d55a61
)
Co-authored-by: Steve Dower <steve.dower@python.org>
This commit is contained in:
parent
e259a77f21
commit
04bcfe001c
3 changed files with 29 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue