Commit c6c6548a authored by Senthil Kumaran's avatar Senthil Kumaran

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

parent 7c5b8c91
...@@ -27,9 +27,12 @@ def url2pathname(url): ...@@ -27,9 +27,12 @@ def url2pathname(url):
drive = comp[0][-1].upper() drive = comp[0][-1].upper()
components = comp[1].split('/') components = comp[1].split('/')
path = drive + ':' path = drive + ':'
for comp in components: for comp in components:
if comp: if comp:
path = path + '\\' + urllib.parse.unquote(comp) path = path + '\\' + urllib.parse.unquote(comp)
# Issue #11474 - handing url such as |c/|
if path.endswith(':') and url.endswith('/'):
path += '\\'
return path return path
def pathname2url(p): def pathname2url(p):
......
...@@ -9,6 +9,7 @@ import io ...@@ -9,6 +9,7 @@ import io
import unittest import unittest
from test import support from test import support
import os import os
import sys
import tempfile import tempfile
import warnings import warnings
...@@ -995,6 +996,23 @@ class Pathname_Tests(unittest.TestCase): ...@@ -995,6 +996,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 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): 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."""
......
...@@ -51,6 +51,9 @@ Core and Builtins ...@@ -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 to work properly even when _json is not available. - 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 - Issue #11703: urllib2.geturl() does not return correct url when the original
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment