From: Senthil Kumaran Date: Thu, 14 Apr 2011 05:16:30 +0000 (+0800) Subject: Fix Issue11474 - fix url2pathname() handling of '/C|/' on Windows X-Git-Tag: v3.2.1b1~128^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d2ea1b431f9cf58aa8ac45052bd2e4cf2502a5c;p=python Fix Issue11474 - fix url2pathname() handling of '/C|/' on Windows --- diff --git a/Lib/nturl2path.py b/Lib/nturl2path.py index ce9c3d36db..511dcec5d6 100644 --- a/Lib/nturl2path.py +++ b/Lib/nturl2path.py @@ -27,9 +27,12 @@ def url2pathname(url): drive = comp[0][-1].upper() components = comp[1].split('/') path = drive + ':' - for comp in components: + for comp in components: if comp: path = path + '\\' + urllib.parse.unquote(comp) + # Issue #11474 - handing url such as |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 index 462a2b03f8..4d3509ae7d 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -9,6 +9,7 @@ import io import unittest from test import support import os +import sys import tempfile import warnings @@ -995,6 +996,23 @@ class Pathname_Tests(unittest.TestCase): "url2pathname() failed; %s != %s" % (expect, result)) + @unittest.skipUnless(sys.platform == 'win32', + 'test specific to the urllib.url2path function.') + def test_ntpath(self): + given = ('/C:/', '///C:/', '/C|//') + expect = 'C:\\' + for url in given: + result = urllib.request.url2pathname(url) + self.assertEqual(expect, result, + 'urllib.request..url2pathname() failed; %s != %s' % + (expect, result)) + given = '///C|/path' + expect = 'C:\\path' + result = urllib.request.url2pathname(given) + self.assertEqual(expect, result, + 'urllib.request.url2pathname() failed; %s != %s' % + (expect, result)) + class Utility_Tests(unittest.TestCase): """Testcase to test the various utility functions in the urllib.""" diff --git a/Misc/NEWS b/Misc/NEWS index 6a4da30c3f..8764b1131f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -51,6 +51,9 @@ Core and Builtins Library ------- +- Issue #11474: Fix the bug with url2pathname() handling of '/C|/' on Windows. + Patch by Santoso Wijaya. + - Issue #9233: Fix json to work properly even when _json is not available. - Issue #11703: urllib2.geturl() does not return correct url when the original