Skip to content

Commit 8c98ed8

Browse files
authored
pythonGH-127078: url2pathname(): handle extra slash before UNC drive in URL path (python#127132)
Decode a file URI like `file://///server/share` as a UNC path like `\\server\share`. This form of file URI is created by software the simply prepends `file:///` to any absolute Windows path.
1 parent ebf564a commit 8c98ed8

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Lib/nturl2path.py

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def url2pathname(url):
2222
elif url[:12] == '//localhost/':
2323
# Skip past 'localhost' authority.
2424
url = url[11:]
25+
if url[:3] == '///':
26+
# Skip past extra slash before UNC drive in URL path.
27+
url = url[1:]
2528
# Windows itself uses ":" even in URLs.
2629
url = url.replace(':', '|')
2730
if not '|' in url:

Lib/test/test_urllib.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ def test_url2pathname_win(self):
14921492
# UNC paths
14931493
self.assertEqual(fn('//server/path/to/file'), '\\\\server\\path\\to\\file')
14941494
self.assertEqual(fn('////server/path/to/file'), '\\\\server\\path\\to\\file')
1495-
self.assertEqual(fn('/////server/path/to/file'), '\\\\\\server\\path\\to\\file')
1495+
self.assertEqual(fn('/////server/path/to/file'), '\\\\server\\path\\to\\file')
14961496
# Localhost paths
14971497
self.assertEqual(fn('//localhost/C:/path/to/file'), 'C:\\path\\to\\file')
14981498
self.assertEqual(fn('//localhost/C|/path/to/file'), 'C:\\path\\to\\file')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix issue where :func:`urllib.request.url2pathname` failed to discard an
2+
extra slash before a UNC drive in the URL path on Windows.

0 commit comments

Comments
 (0)