Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d2ea1b

Browse files
committed
Fix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
1 parent 95cd91c commit 2d2ea1b

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

Lib/nturl2path.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ def url2pathname(url):
2727
drive = comp[0][-1].upper()
2828
components = comp[1].split('/')
2929
path = drive + ':'
30-
for comp in components:
30+
for comp in components:
3131
if comp:
3232
path = path + '\\' + urllib.parse.unquote(comp)
33+
# Issue #11474 - handing url such as |c/|
34+
if path.endswith(':') and url.endswith('/'):
35+
path += '\\'
3336
return path
3437

3538
def pathname2url(p):

Lib/test/test_urllib.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import unittest
1010
from test import support
1111
import os
12+
import sys
1213
import tempfile
1314
import warnings
1415

@@ -995,6 +996,23 @@ def test_quoting(self):
995996
"url2pathname() failed; %s != %s" %
996997
(expect, result))
997998

999+
@unittest.skipUnless(sys.platform == 'win32',
1000+
'test specific to the urllib.url2path function.')
1001+
def test_ntpath(self):
1002+
given = ('/C:/', '///C:/', '/C|//')
1003+
expect = 'C:\\'
1004+
for url in given:
1005+
result = urllib.request.url2pathname(url)
1006+
self.assertEqual(expect, result,
1007+
'urllib.request..url2pathname() failed; %s != %s' %
1008+
(expect, result))
1009+
given = '///C|/path'
1010+
expect = 'C:\\path'
1011+
result = urllib.request.url2pathname(given)
1012+
self.assertEqual(expect, result,
1013+
'urllib.request.url2pathname() failed; %s != %s' %
1014+
(expect, result))
1015+
9981016
class Utility_Tests(unittest.TestCase):
9991017
"""Testcase to test the various utility functions in the urllib."""
10001018

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ Core and Builtins
5151
Library
5252
-------
5353

54+
- Issue #11474: Fix the bug with url2pathname() handling of '/C|/' on Windows.
55+
Patch by Santoso Wijaya.
56+
5457
- Issue #9233: Fix json to work properly even when _json is not available.
5558

5659
- Issue #11703: urllib2.geturl() does not return correct url when the original

0 commit comments

Comments
 (0)