Skip to content

Commit 4c46ba3

Browse files
committed
GH-123599: Remove duplicate url2pathname() implementation
Call `urllib.request.url2pathname()` from `pathlib.Path.from_uri()` rather than re-implementing it. This paves the way for solving the main issue (ignoring local authorities and rejecting non-local ones) in urllib, not pathlib.
1 parent 307c633 commit 4c46ba3

1 file changed

Lines changed: 2 additions & 15 deletions

File tree

Lib/pathlib/_local.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -905,21 +905,8 @@ def from_uri(cls, uri):
905905
"""Return a new path from the given 'file' URI."""
906906
if not uri.startswith('file:'):
907907
raise ValueError(f"URI does not start with 'file:': {uri!r}")
908-
path = uri[5:]
909-
if path[:3] == '///':
910-
# Remove empty authority
911-
path = path[2:]
912-
elif path[:12] == '//localhost/':
913-
# Remove 'localhost' authority
914-
path = path[11:]
915-
if path[:3] == '///' or (path[:1] == '/' and path[2:3] in ':|'):
916-
# Remove slash before DOS device/UNC path
917-
path = path[1:]
918-
if path[1:2] == '|':
919-
# Replace bar with colon in DOS drive
920-
path = path[:1] + ':' + path[2:]
921-
from urllib.parse import unquote_to_bytes
922-
path = cls(os.fsdecode(unquote_to_bytes(path)))
908+
from urllib.request import url2pathname
909+
path = cls(url2pathname(uri.removeprefix('file:')))
923910
if not path.is_absolute():
924911
raise ValueError(f"URI is not absolute: {uri!r}")
925912
return path

0 commit comments

Comments
 (0)