Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,11 @@ def url2pathname(url, *, require_scheme=False, resolve_host=False):
"""
if not require_scheme:
url = 'file:' + url
# Handle Windows file URLs with backslashes like file:\\C:\path
# (as used in some browsers and in the wild). Normalize to forward
# slashes before parsing so urlsplit treats it as file://.
if url.lower().startswith('file:'):
url = url.replace('\\', '/')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to just replace file:\\ with file:// on Windows only to avoid accepting invalid uris like file://Users/edvilme\somepath

scheme, authority, url = urlsplit(url)[:3] # Discard query and fragment.
if scheme != 'file':
raise URLError("URL is missing a 'file:' scheme")
Expand Down
Loading