mirror of
https://github.com/python/cpython.git
synced 2025-08-31 22:18:28 +00:00
GH-123599: url2pathname()
: handle authority section in file URL (#126844)
In `urllib.request.url2pathname()`, if the authority resolves to the current host, discard it. If an authority is present but resolves somewhere else, then on Windows we return a UNC path (as before), and on other platforms we raise `URLError`. Affects `pathlib.Path.from_uri()` in the same way. Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
a214db0c54
commit
66cdb2bd8a
8 changed files with 106 additions and 48 deletions
|
@ -3285,10 +3285,14 @@ class PathTest(PurePathTest):
|
|||
def test_from_uri_posix(self):
|
||||
P = self.cls
|
||||
self.assertEqual(P.from_uri('file:/foo/bar'), P('/foo/bar'))
|
||||
self.assertEqual(P.from_uri('file://foo/bar'), P('//foo/bar'))
|
||||
self.assertRaises(ValueError, P.from_uri, 'file://foo/bar')
|
||||
self.assertEqual(P.from_uri('file:///foo/bar'), P('/foo/bar'))
|
||||
self.assertEqual(P.from_uri('file:////foo/bar'), P('//foo/bar'))
|
||||
self.assertEqual(P.from_uri('file://localhost/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(f'file://{socket.gethostname()}/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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue