]> granicus.if.org Git - python/commitdiff
Fix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
authorSenthil Kumaran <orsenthil@gmail.com>
Thu, 14 Apr 2011 05:16:30 +0000 (13:16 +0800)
committerSenthil Kumaran <orsenthil@gmail.com>
Thu, 14 Apr 2011 05:16:30 +0000 (13:16 +0800)
Lib/nturl2path.py
Lib/test/test_urllib.py
Misc/NEWS

index ce9c3d36dba359c722b1a936ed5f396f383e637b..511dcec5d66429ee29451d8bd6d839403c7a3721 100644 (file)
@@ -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):
index 462a2b03f83428dfc0b4321fa331470911e23e26..4d3509ae7d2f1726910745f4a9a9f1a06ed39af8 100644 (file)
@@ -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."""
 
index 6a4da30c3fa00171593604670457a977dcb0c3f9..8764b1131f314b9471f611bb7976dec6a67737bc 100644 (file)
--- 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