Skip to content

Commit 7bbcd32

Browse files
[3.13] GH-127078: url2pathname(): handle extra slash before UNC drive in URL path (GH-127132) (#127135)
GH-127078: `url2pathname()`: handle extra slash before UNC drive in URL path (GH-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. (cherry picked from commit 8c98ed8) Co-authored-by: Barney Gale <[email protected]>
1 parent 4b9068e commit 7bbcd32

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
@@ -1591,7 +1591,7 @@ def test_url2pathname_win(self):
15911591
# UNC paths
15921592
self.assertEqual(fn('//server/path/to/file'), '\\\\server\\path\\to\\file')
15931593
self.assertEqual(fn('////server/path/to/file'), '\\\\server\\path\\to\\file')
1594-
self.assertEqual(fn('/////server/path/to/file'), '\\\\\\server\\path\\to\\file')
1594+
self.assertEqual(fn('/////server/path/to/file'), '\\\\server\\path\\to\\file')
15951595
# Localhost paths
15961596
self.assertEqual(fn('//localhost/C:/path/to/file'), 'C:\\path\\to\\file')
15971597
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)