mirror of
https://github.com/python/cpython.git
synced 2025-08-08 10:58:51 +00:00
[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 8c98ed846a
)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
parent
4b705f50d1
commit
c470e822bf
3 changed files with 6 additions and 1 deletions
|
@ -22,6 +22,9 @@ def url2pathname(url):
|
|||
elif url[:12] == '//localhost/':
|
||||
# Skip past 'localhost' authority.
|
||||
url = url[11:]
|
||||
if url[:3] == '///':
|
||||
# Skip past extra slash before UNC drive in URL path.
|
||||
url = url[1:]
|
||||
# Windows itself uses ":" even in URLs.
|
||||
url = url.replace(':', '|')
|
||||
if not '|' in url:
|
||||
|
|
|
@ -1600,7 +1600,7 @@ class Pathname_Tests(unittest.TestCase):
|
|||
# UNC paths
|
||||
self.assertEqual(fn('//server/path/to/file'), '\\\\server\\path\\to\\file')
|
||||
self.assertEqual(fn('////server/path/to/file'), '\\\\server\\path\\to\\file')
|
||||
self.assertEqual(fn('/////server/path/to/file'), '\\\\\\server\\path\\to\\file')
|
||||
self.assertEqual(fn('/////server/path/to/file'), '\\\\server\\path\\to\\file')
|
||||
# Localhost paths
|
||||
self.assertEqual(fn('//localhost/C:/path/to/file'), 'C:\\path\\to\\file')
|
||||
self.assertEqual(fn('//localhost/C|/path/to/file'), 'C:\\path\\to\\file')
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix issue where :func:`urllib.request.url2pathname` failed to discard an
|
||||
extra slash before a UNC drive in the URL path on Windows.
|
Loading…
Add table
Add a link
Reference in a new issue