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

index 29ea80f9d9e9e09001e41b4c92ea45e1e3017627..10ea27280789f5a6bcfc7a2fb6c94ab6b9df5645 100644 (file)
@@ -25,11 +25,14 @@ def url2pathname(url):
         error = 'Bad URL: ' + url
         raise IOError, error
     drive = comp[0][-1].upper()
-    components = comp[1].split('/')
     path = drive + ':'
-    for  comp in components:
+    components = comp[1].split('/')
+    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):
index 7bf383f6bc04c3d5b50d0da1ac116e821bf63519..e7e54a2dd89d178045b11ba84f26e4e455ce5ef5 100644 (file)
@@ -5,6 +5,7 @@ import httplib
 import unittest
 from test import test_support
 import os
+import sys
 import mimetools
 import tempfile
 import StringIO
@@ -630,6 +631,23 @@ class Pathname_Tests(unittest.TestCase):
                          "url2pathname() failed; %s != %s" %
                          (expect, result))
 
+    @unittest.skipUnless(sys.platform == 'win32',
+                         'test specific to the nturl2path library')
+    def test_ntpath(self):
+        given = ('/C:/', '///C:/', '/C|//')
+        expect = 'C:\\'
+        for url in given:
+            result = urllib.url2pathname(url)
+            self.assertEqual(expect, result,
+                             'nturl2path.url2pathname() failed; %s != %s' %
+                             (expect, result))
+        given = '///C|/path'
+        expect = 'C:\\path'
+        result = urllib.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."""
 
index 4718a69b1c32583f66ebd5537e186aaffff41e6f..20fa4179249f97700d523537870cb22e0b652fc1 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.loads('{}') to return a dict (instead of a list), when
   _json is not available.