From d9e0939cccfdd9ccf12d86df8b5f0ebdb2c5a89e Mon Sep 17 00:00:00 2001 From: barneygale Date: Mon, 14 Apr 2025 02:07:04 +0100 Subject: [PATCH 1/3] GH-90812: Add test for `urlopen()` of file URI for UNC path --- Lib/test/test_urllib.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index abfbed8840ca03..eacc70adea1631 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -183,6 +183,17 @@ def test_iter(self): 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.reason, 'File not found') + 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): From 5b507b950e3d4ec4eed8641f64507e3d5dc1a7c4 Mon Sep 17 00:00:00 2001 From: barneygale Date: Mon, 14 Apr 2025 02:13:21 +0100 Subject: [PATCH 2/3] Fix test --- Lib/test/test_urllib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index eacc70adea1631..0aeffc19d5f103 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -189,7 +189,7 @@ def test_remote_authority(self): with self.assertRaises(urllib.error.URLError) as e: urllib.request.urlopen(url) if os.name == 'nt': - self.assertEqual(e.exception.reason, 'File not found') + self.assertEqual(e.exception.reason, 'The network path was not found') self.assertEqual(e.exception.filename, r'\\pythontest.net\foo\bar') else: self.assertEqual(e.exception.reason, 'file:// scheme is supported only on localhost') From d86cbc6c13734ab2a50f139fbef1397182079602 Mon Sep 17 00:00:00 2001 From: barneygale Date: Mon, 14 Apr 2025 02:25:15 +0100 Subject: [PATCH 3/3] Don't test localised OS error string --- Lib/test/test_urllib.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 0aeffc19d5f103..7d1afbcb88a0ed 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -189,7 +189,6 @@ def test_remote_authority(self): with self.assertRaises(urllib.error.URLError) as e: urllib.request.urlopen(url) if os.name == 'nt': - self.assertEqual(e.exception.reason, 'The network path was not found') self.assertEqual(e.exception.filename, r'\\pythontest.net\foo\bar') else: self.assertEqual(e.exception.reason, 'file:// scheme is supported only on localhost')