File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,9 +27,12 @@ def url2pathname(url):
2727 drive = comp [0 ][- 1 ].upper ()
2828 components = comp [1 ].split ('/' )
2929 path = drive + ':'
30- for comp in components :
30+ for comp in components :
3131 if comp :
3232 path = path + '\\ ' + urllib .parse .unquote (comp )
33+ # Issue #11474 - handing url such as |c/|
34+ if path .endswith (':' ) and url .endswith ('/' ):
35+ path += '\\ '
3336 return path
3437
3538def pathname2url (p ):
Original file line number Diff line number Diff line change 99import unittest
1010from test import support
1111import os
12+ import sys
1213import tempfile
1314import warnings
1415
@@ -995,6 +996,23 @@ def test_quoting(self):
995996 "url2pathname() failed; %s != %s" %
996997 (expect , result ))
997998
999+ @unittest .skipUnless (sys .platform == 'win32' ,
1000+ 'test specific to the urllib.url2path function.' )
1001+ def test_ntpath (self ):
1002+ given = ('/C:/' , '///C:/' , '/C|//' )
1003+ expect = 'C:\\ '
1004+ for url in given :
1005+ result = urllib .request .url2pathname (url )
1006+ self .assertEqual (expect , result ,
1007+ 'urllib.request..url2pathname() failed; %s != %s' %
1008+ (expect , result ))
1009+ given = '///C|/path'
1010+ expect = 'C:\\ path'
1011+ result = urllib .request .url2pathname (given )
1012+ self .assertEqual (expect , result ,
1013+ 'urllib.request.url2pathname() failed; %s != %s' %
1014+ (expect , result ))
1015+
9981016class Utility_Tests (unittest .TestCase ):
9991017 """Testcase to test the various utility functions in the urllib."""
10001018
Original file line number Diff line number Diff line change @@ -51,6 +51,9 @@ Core and Builtins
5151Library
5252-------
5353
54+ - Issue #11474: Fix the bug with url2pathname() handling of '/C|/' on Windows.
55+ Patch by Santoso Wijaya.
56+
5457- Issue #9233: Fix json to work properly even when _json is not available.
5558
5659- Issue #11703: urllib2.geturl() does not return correct url when the original
You can’t perform that action at this time.
0 commit comments