Fix Issue11474 - url2pathname() handling of '/C|/' on Windows
This commit is contained in:
parent
7f9d2ead34
commit
a99b761972
|
@ -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):
|
||||
|
|
|
@ -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."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue