Fix Issue11474 - url2pathname() handling of '/C|/' on Windows

This commit is contained in:
Senthil Kumaran 2011-04-14 12:54:35 +08:00
parent 7f9d2ead34
commit a99b761972
3 changed files with 26 additions and 2 deletions

View File

@ -25,11 +25,14 @@ def url2pathname(url):
error = 'Bad URL: ' + url error = 'Bad URL: ' + url
raise IOError, error raise IOError, error
drive = comp[0][-1].upper() drive = comp[0][-1].upper()
components = comp[1].split('/')
path = drive + ':' path = drive + ':'
components = comp[1].split('/')
for comp in components: for comp in components:
if comp: if comp:
path = path + '\\' + urllib.unquote(comp) path = path + '\\' + urllib.unquote(comp)
# Issue #11474: url like '/C|/' should convert into 'C:\\'
if path.endswith(':') and url.endswith('/'):
path += '\\'
return path return path
def pathname2url(p): def pathname2url(p):

View File

@ -5,6 +5,7 @@ import httplib
import unittest import unittest
from test import test_support from test import test_support
import os import os
import sys
import mimetools import mimetools
import tempfile import tempfile
import StringIO import StringIO
@ -630,6 +631,23 @@ class Pathname_Tests(unittest.TestCase):
"url2pathname() failed; %s != %s" % "url2pathname() failed; %s != %s" %
(expect, result)) (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): class Utility_Tests(unittest.TestCase):
"""Testcase to test the various utility functions in the urllib.""" """Testcase to test the various utility functions in the urllib."""

View File

@ -51,6 +51,9 @@ Core and Builtins
Library 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 - Issue #9233: Fix json.loads('{}') to return a dict (instead of a list), when
_json is not available. _json is not available.