diff --git a/Lib/nturl2path.py b/Lib/nturl2path.py old mode 100644 new mode 100755 --- a/Lib/nturl2path.py +++ b/Lib/nturl2path.py @@ -25,11 +25,14 @@ error = 'Bad URL: ' + url raise IOError, error drive = comp[0][-1].upper() + path = drive + ':' components = comp[1].split('/') - path = drive + ':' - for comp in components: + for comp in components: if comp: path = path + '\\' + urllib.unquote(comp) + # Issue #11474: url like '/C|/' should convert into 'C:\\' + if path.endswith(':') and url.endswith('/'): + path += '\\' return path def pathname2url(p): diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py old mode 100644 new mode 100755 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -5,6 +5,7 @@ import unittest from test import test_support import os +import sys import mimetools import tempfile import StringIO @@ -606,6 +607,26 @@ "url2pathname() failed; %s != %s" % (expect, result)) + @unittest.skipUnless(sys.platform == 'win32', + 'test specific to the nturl2path library') + def test_ntpath(self): + from nturl2path import url2pathname + + given = ('/C:/', '///C:/', '/C|//') + expect = 'C:\\' + for url in given: + result = url2pathname(url) + self.assertEqual(expect, result, + 'nturl2path.url2pathname() failed; %s != %s' % + (expect, result)) + + given = '///C|/path' + expect = 'C:\\path' + result = url2pathname(given) + self.assertEqual(expect, result, + 'nturl2path.url2pathname() failed; %s != %s' % + (expect, result)) + class Utility_Tests(unittest.TestCase): """Testcase to test the various utility functions in the urllib."""