diff --git a/Lib/nturl2path.py b/Lib/nturl2path.py index 7e13ae3128333d..e5667bc9a3ca94 100644 --- a/Lib/nturl2path.py +++ b/Lib/nturl2path.py @@ -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: diff --git a/Misc/NEWS.d/next/Library/2024-12-07-22-59-49.gh-issue-126367.re6HS2.rst b/Misc/NEWS.d/next/Library/2024-12-07-22-59-49.gh-issue-126367.re6HS2.rst new file mode 100644 index 00000000000000..1bf8e71d83c3f2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-12-07-22-59-49.gh-issue-126367.re6HS2.rst @@ -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.