diff -r 24179f82b7de Lib/nturl2path.py --- a/Lib/nturl2path.py Tue Mar 22 23:47:32 2011 +0100 +++ b/Lib/nturl2path.py Sun Mar 27 14:33:07 2011 -0700 @@ -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 -r 24179f82b7de Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py Tue Mar 22 23:47:32 2011 +0100 +++ b/Lib/test/test_urllib.py Sun Mar 27 14:33:07 2011 -0700 @@ -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."""