Skip to content

Commit c470e82

Browse files
[3.12] GH-127078: url2pathname(): handle extra slash before UNC drive in URL path (GH-127132) (#127136)
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 4b705f5 commit c470e82

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
@@ -1600,7 +1600,7 @@ def test_url2pathname_win(self):
16001600
# UNC paths
16011601
self.assertEqual(fn('//server/path/to/file'), '\\\\server\\path\\to\\file')
16021602
self.assertEqual(fn('////server/path/to/file'), '\\\\server\\path\\to\\file')
1603-
self.assertEqual(fn('/////server/path/to/file'), '\\\\\\server\\path\\to\\file')
1603+
self.assertEqual(fn('/////server/path/to/file'), '\\\\server\\path\\to\\file')
16041604
# Localhost paths
16051605
self.assertEqual(fn('//localhost/C:/path/to/file'), 'C:\\path\\to\\file')
16061606
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)