File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -44,20 +44,21 @@ def pathname2url(p):
4444 import urllib .parse
4545 # First, clean up some special forms. We are going to sacrifice
4646 # the additional information anyway
47- if p [:4 ] == '\\ \\ ?\\ ' :
47+ p = p .replace ('\\ ' , '/' )
48+ if p [:4 ] == '//?/' :
4849 p = p [4 :]
49- if p [:4 ].upper () == 'UNC\\ ' :
50- p = '\\ \\ ' + p [4 :]
50+ if p [:4 ].upper () == 'UNC/ ' :
51+ p = '// ' + p [4 :]
5152 elif p [1 :2 ] != ':' :
5253 raise OSError ('Bad path: ' + p )
5354 if not ':' in p :
54- # No drive specifier , just convert slashes and quote the name
55- return urllib .parse .quote (p . replace ( ' \\ ' , '/' ) )
55+ # No DOS drive specified , just quote the pathname
56+ return urllib .parse .quote (p )
5657 comp = p .split (':' , maxsplit = 2 )
5758 if len (comp ) != 2 or len (comp [0 ]) > 1 :
5859 error = 'Bad path: ' + p
5960 raise OSError (error )
6061
6162 drive = urllib .parse .quote (comp [0 ].upper ())
62- tail = urllib .parse .quote (comp [1 ]. replace ( ' \\ ' , '/' ) )
63+ tail = urllib .parse .quote (comp [1 ])
6364 return '///' + drive + ':' + tail
Original file line number Diff line number Diff line change @@ -1542,6 +1542,11 @@ def test_pathname2url_win(self):
15421542 self .assertEqual (fn ('\\ \\ some\\ share\\ ' ), '//some/share/' )
15431543 self .assertEqual (fn ('\\ \\ some\\ share\\ a\\ b.c' ), '//some/share/a/b.c' )
15441544 self .assertEqual (fn ('\\ \\ some\\ share\\ a\\ b%#c\xe9 ' ), '//some/share/a/b%25%23c%C3%A9' )
1545+ # Alternate path separator
1546+ self .assertEqual (fn ('C:/a/b.c' ), '///C:/a/b.c' )
1547+ self .assertEqual (fn ('//some/share/a/b.c' ), '//some/share/a/b.c' )
1548+ self .assertEqual (fn ('//?/C:/dir' ), '///C:/dir' )
1549+ self .assertEqual (fn ('//?/unc/server/share/dir' ), '//server/share/dir' )
15451550 # Round-tripping
15461551 urls = ['///C:' ,
15471552 '///folder/test/' ,
Original file line number Diff line number Diff line change 1+ Fix issue where :func: `urllib.request.pathname2url ` mishandled Windows paths
2+ with embedded forward slashes.
You can’t perform that action at this time.
0 commit comments