8000 GH-123599: Reject non-local authority in `pathlib.Path.from_uri()` on POSIX by barneygale · Pull Request #123650 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-123599: Reject non-local authority in pathlib.Path.from_uri() on POSIX #123650

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 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Fix WASI
  • Loading branch information
barneygale committed Oct 20, 2024
commit 38233cdeb21a6013cafc66d61401612b112cdd27
2 changes: 2 additions & 0 deletions Lib/pathlib/_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ def is_local_authority(authority):
authority = socket.gethostbyname(authority)
except socket.gaierror:
return False
except AttributeError:
return False # WASI doesn't have gethostbyname()

if _local_authorities is None:
try:
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1711,8 +1711,9 @@ def test_from_uri_posix(self):
self.assertEqual(P.from_uri('file:////foo/bar'), P('//foo/bar'))
self.assertEqual(P.from_uri('file://localhost/foo/bar'), P('/foo/bar'))
self.assertEqual(P.from_uri('file://localhost//foo/bar'), P('//foo/bar'))
self.assertEqual(P.from_uri('file://127.0.0.1/foo/bar'), P('/foo/bar'))
self.assertEqual(P.from_uri('file://127.0.0.1//foo/bar'), P('//foo/bar'))
if not is_wasi:
self.assertEqual(P.from_uri('file://127.0.0.1/foo/bar'), P('/foo/bar'))
self.assertEqual(P.from_uri('file://127.0.0.1//foo/bar'), P('//foo/bar'))
self.assertRaises(ValueError, P.from_uri, 'foo/bar')
self.assertRaises(ValueError, P.from_uri, '/foo/bar')
self.assertRaises(ValueError, P.from_uri, '//foo/bar')
Expand Down
Loading
0