Skip to content

Commit 372a378

Browse files
committed
fixed colon handling for windows urls
1 parent d8d12b3 commit 372a378

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Lib/nturl2path.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ def url2pathname(url):
2626
# Skip past extra slash before UNC drive in URL path.
2727
url = url[1:]
2828
# Windows itself uses ":" even in URLs.
29-
url = url.replace(':', '|')
30-
if not '|' in url:
29+
url = url.replace(':', '|', 1)
30+
if not '|' in url or ('|' in url and not (
31+
url.startswith('|') or
32+
'/|' in url or
33+
(len(url) > 2 and url[0] == '/' and url[2] == '|' and url[1].isalpha()))
34+
):
35+
url = url.replace('|', ':', 1)
3136
# No drive specifier, just convert slashes
3237
# make sure not to convert quoted slashes :-)
3338
return urllib.parse.unquote(url.replace('/', '\\'))

Lib/test/test_urllib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,9 @@ def test_url2pathname_win(self):
15091509
# Percent-encoded forward slashes are preserved for backwards compatibility
15101510
self.assertEqual(fn('C:/foo%2fbar'), 'C:\\foo/bar')
15111511
self.assertEqual(fn('//server/share/foo%2fbar'), '\\\\server\\share\\foo/bar')
1512+
# Colon in filenames, both with drive specifier and without
1513+
self.assertEqual(fn('//host/path/spam.foo:bar'), '\\\\host\\path\\spam.foo:bar')
1514+
self.assertEqual(fn('///c:/path/spam.foo:bar'), 'c:\\path\\spam.foo:bar')
15121515
# Round-tripping
15131516
paths = ['C:',
15141517
r'\C\test\\',

0 commit comments

Comments
 (0)