]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-90812: Add test for `urlopen()` of file URI for UNC path (#132489)
authorBarney Gale <barney.gale@gmail.com>
Tue, 15 Apr 2025 18:16:34 +0000 (19:16 +0100)
committerGitHub <noreply@github.com>
Tue, 15 Apr 2025 18:16:34 +0000 (19:16 +0100)
Lib/test/test_urllib.py

index da3db2f4e550fb8737b186362b856e7a53034271..90de828cc71249d05c52df37b0374e8aba33f879 100644 (file)
@@ -181,6 +181,16 @@ class urlopen_FileTests(unittest.TestCase):
     def test_relativelocalfile(self):
         self.assertRaises(ValueError,urllib.request.urlopen,'./' + self.pathname)
 
+    def test_remote_authority(self):
+        # Test for GH-90812.
+        url = 'file://pythontest.net/foo/bar'
+        with self.assertRaises(urllib.error.URLError) as e:
+            urllib.request.urlopen(url)
+        if os.name == 'nt':
+            self.assertEqual(e.exception.filename, r'\\pythontest.net\foo\bar')
+        else:
+            self.assertEqual(e.exception.reason, 'file:// scheme is supported only on localhost')
+
 
 class ProxyTests(unittest.TestCase):