@@ -43,17 +43,23 @@ def pathname2url(p):
4343 # ///C:/foo/bar/spam.foo
4444 import ntpath
4545 import urllib .parse
46- # First, clean up some special forms. We are going to sacrifice
47- # the additional information anyway
48- p = p .replace ('\\ ' , '/' )
49- if p [:4 ] == '//?/' :
50- p = p [4 :]
51- if p [:4 ].upper () == 'UNC/' :
52- p = '//' + p [4 :]
53- drive , tail = ntpath .splitdrive (p )
54- if drive [1 :2 ] != ':' :
55- # No DOS drive specified, just quote the pathname
56- return urllib .parse .quote (p )
57- drive = urllib .parse .quote (drive [0 ].upper ())
58- tail = urllib .parse .quote (tail )
59- return '///' + drive + ':' + tail
46+ drive , tail = ntpath .splitdrive (p .replace ('\\ ' , '/' ))
47+ if drive :
48+ # First, clean up some special forms. We are going to sacrifice the
49+ # additional information anyway.
50+ if drive [:4 ] == '//?/' :
51+ drive = drive [4 :]
52+ if drive [:4 ].upper () == 'UNC/' :
53+ drive = '//' + drive [4 :]
54+
55+ if drive [1 :2 ] == ':' :
56+ # DOS drive specified. Add three slashes to the start, producing
57+ # an authority section with a zero-length authority, and a path
58+ # section starting with a single slash. The colon is *not* quoted.
59+ letter = urllib .parse .quote (drive [0 ].upper ())
60+ drive = f'///{ letter } :'
61+ else :
62+ # No DOS drive specified, just quote the pathname.
63+ drive = urllib .parse .quote (drive )
64+
65+ return drive + urllib .parse .quote (tail )
0 commit comments