Skip to content

GH-126367: Fix urllib.request.url2pathname() colon handling in URLs on Windows #127728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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: 3 additions & 2 deletions Lib/nturl2path.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ def url2pathname(url):
# 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:
url = url.replace(':', '|', 1)
if '|' in url and not (url.startswith('|') or '/|' in url):
# No drive specifier, just convert slashes
# make sure not to convert quoted slashes :-)
url = url.replace('|', ':', 1)
return urllib.parse.unquote(url.replace('/', '\\'))
comp = url.split('|')
if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modified the :func:`~urllib.request.url2pathname` function in :mod:`urllib.request` to correctly handle DOS drive paths in URLs on Windows. Previously, the function produced incorrect results for UNC paths and raised OS errors for some paths.
Loading