]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] GH-127078: `url2pathname()`: handle extra slash before UNC drive in URL path...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 22 Nov 2024 04:37:51 +0000 (05:37 +0100)
committerGitHub <noreply@github.com>
Fri, 22 Nov 2024 04:37:51 +0000 (04:37 +0000)
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 8c98ed846a7d7e50c4cf06f823d94737144dcf6a)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Lib/nturl2path.py
Lib/test/test_urllib.py
Misc/NEWS.d/next/Library/2024-11-22-03-40-02.gh-issue-127078.gI_PaP.rst [new file with mode: 0644]

index 6e0d26c129cb9995aab5c6e43c4ca4a369c02d34..757fd01bec822380804e29d81a8a43012d992caf 100644 (file)
@@ -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:
index 4520f8c85e6b03e9e4d54615f91ad054fabe8f61..4bdbc19c1ffb7a46a534bab947f4c8a7db32af49 100644 (file)
@@ -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')
diff --git a/Misc/NEWS.d/next/Library/2024-11-22-03-40-02.gh-issue-127078.gI_PaP.rst b/Misc/NEWS.d/next/Library/2024-11-22-03-40-02.gh-issue-127078.gI_PaP.rst
new file mode 100644 (file)
index 0000000..a84c06f
--- /dev/null
@@ -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.