Skip to content

Commit 56f1e2d

Browse files
committed
merge from 3.1
2 parents c1f0577 + 2d2ea1b commit 56f1e2d

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

1415
def hexescape(char):
@@ -1021,6 +1022,23 @@ def test_quoting(self):
10211022
"url2pathname() failed; %s != %s" %
10221023
(expect, result))
10231024

1025+
@unittest.skipUnless(sys.platform == 'win32',
1026+
'test specific to the urllib.url2path function.')
1027+
def test_ntpath(self):
1028+
given = ('/C:/', '///C:/', '/C|//')
1029+
expect = 'C:\\'
1030+
for url in given:
1031+
result = urllib.request.url2pathname(url)
1032+
self.assertEqual(expect, result,
1033+
'urllib.request..url2pathname() failed; %s != %s' %
1034+
(expect, result))
1035+
given = '///C|/path'
1036+
expect = 'C:\\path'
1037+
result = urllib.request.url2pathname(given)
1038+
self.assertEqual(expect, result,
1039+
'urllib.request.url2pathname() failed; %s != %s' %
1040+
(expect, result))
1041+
10241042
class Utility_Tests(unittest.TestCase):
10251043
"""Testcase to test the various utility functions in the urllib."""
10261044

Misc/NEWS

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

56+
- Issue #11474: Fix the bug with url2pathname() handling of '/C|/' on Windows.
57+
Patch by Santoso Wijaya.
58+
5659
- Issue #9233: Fix json.loads('{}') to return a dict (instead of a list), when
5760
_json is not available.
5861

0 commit comments

Comments
 (0)