[Python-checkins] cpython (2.7): Fix Issue11474 - url2pathname() handling of '/C|/' on Windows
senthil.kumaran
python-checkins at python.org
Thu Apr 14 06:59:02 CEST 2011
http://hg.python.org/cpython/rev/4556f17356f2
changeset: 69346:4556f17356f2
branch: 2.7
parent: 69341:5a09a335e8e7
user: Senthil Kumaran <orsenthil at gmail.com>
date: Thu Apr 14 12:54:35 2011 +0800
summary:
Fix Issue11474 - url2pathname() handling of '/C|/' on Windows
files:
Lib/nturl2path.py | 7 +++++--
Lib/test/test_urllib.py | 18 ++++++++++++++++++
Misc/NEWS | 3 +++
3 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/Lib/nturl2path.py b/Lib/nturl2path.py
--- a/Lib/nturl2path.py
+++ b/Lib/nturl2path.py
@@ -25,11 +25,14 @@
error = 'Bad URL: ' + url
raise IOError, error
drive = comp[0][-1].upper()
+ path = drive + ':'
components = comp[1].split('/')
- path = drive + ':'
- for comp in components:
+ 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):
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -5,6 +5,7 @@
import unittest
from test import test_support
import os
+import sys
import mimetools
import tempfile
import StringIO
@@ -630,6 +631,23 @@
"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."""
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -51,6 +51,9 @@
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.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list