Skip to content

Commit aeb55eb

Browse files
[3.14] GH-137059: url2pathname(): fix support for drive letter in netloc (GH-137060) (#137144)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
1 parent fbc2a0c commit aeb55eb

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Lib/test/test_urllib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,10 @@ def test_url2pathname_resolve_host(self):
15901590
def test_url2pathname_win(self):
15911591
fn = urllib.request.url2pathname
15921592
self.assertEqual(fn('/C:/'), 'C:\\')
1593+
self.assertEqual(fn('//C:'), 'C:')
1594+
self.assertEqual(fn('//C:/'), 'C:\\')
1595+
self.assertEqual(fn('//C:\\'), 'C:\\')
1596+
self.assertEqual(fn('//C:80/'), 'C:80\\')
15931597
self.assertEqual(fn("///C|"), 'C:')
15941598
self.assertEqual(fn("///C:"), 'C:')
15951599
self.assertEqual(fn('///C:/'), 'C:\\')

Lib/urllib/request.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,10 @@ def url2pathname(url, *, require_scheme=False, resolve_host=False):
16601660
if scheme != 'file':
16611661
raise URLError("URL is missing a 'file:' scheme")
16621662
if os.name == 'nt':
1663-
if not _is_local_authority(authority, resolve_host):
1663+
if authority[1:2] == ':':
1664+
# e.g. file://c:/file.txt
1665+
url = authority + url
1666+
elif not _is_local_authority(authority, resolve_host):
16641667
# e.g. file://server/share/file.txt
16651668
url = '//' + authority + url
16661669
elif url[:3] == '///':
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix handling of file URLs with a Windows drive letter in the URL authority
2+
by :func:`urllib.request.url2pathname`. This fixes a regression in earlier
3+
pre-releases of Python 3.14.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy