Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita48d1ec

Browse files
barneygalemiss-islington
authored andcommitted
pythonGH-137059:url2pathname(): fix support for drive letter in netloc (pythonGH-137060)
Support file URLs like `file://c:/foo` in `urllib.request.url2pathname()`on Windows. This restores behaviour from 3.13.(cherry picked from commit10a925c)Co-authored-by: Barney Gale <barney.gale@gmail.com>
1 parent47a2109 commita48d1ec

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
deftest_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
ifscheme!='file':
16611661
raiseURLError("URL is missing a 'file:' scheme")
16621662
ifos.name=='nt':
1663-
ifnot_is_local_authority(authority,resolve_host):
1663+
ifauthority[1:2]==':':
1664+
# e.g. file://c:/file.txt
1665+
url=authority+url
1666+
elifnot_is_local_authority(authority,resolve_host):
16641667
# e.g. file://server/share/file.txt
16651668
url='//'+authority+url
16661669
elifurl[: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)

[8]ページ先頭

©2009-2025 Movatter.jp