https://github.com/python/cpython/commit/1dfd6d55b734fe3a4ccc2234e7df70550f5ab3b1
commit: 1dfd6d55b734fe3a4ccc2234e7df70550f5ab3b1
branch: 3.13
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-09-13T21:18:26Z
summary:

[3.13] gh-156713: Fix test_nturl2path for non-UTF-8 filesystem encodings 
(GH-157461) (GH-157464)

Use os_helper.FS_NONASCII and os_helper.TESTFN_UNDECODABLE instead of
hardcoded UTF-8 results.
(cherry picked from commit fd0970c0ab7eb8c685ef9e5476f36e7d108c19ac)

files:
M Lib/test/test_urllib.py

diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index d0f743178f7819..675e7db03e5c4d 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -1660,14 +1660,17 @@ def test_pathname2url_nonascii(self):
         url = urllib.parse.quote(os_helper.FS_NONASCII, encoding=encoding, 
errors=errors)
         self.assertEqual(urllib.request.pathname2url(os_helper.FS_NONASCII), 
url)
 
+    @unittest.skipUnless(os_helper.TESTFN_UNDECODABLE,
+                         'need os_helper.TESTFN_UNDECODABLE')
     def test_pathname2url_surrogates(self):
         # gh-156713: the filesystem encoding and error handler are used,
         # so that paths containing surrogate characters can be converted.
         encoding = sys.getfilesystemencoding()
         errors = sys.getfilesystemencodeerrors()
-        tail = urllib.parse.quote('a\udcff', encoding=encoding, errors=errors)
-        self.assertEqual(nturl2path.pathname2url('C:\\a\udcff'),
-                         '///C:/' + tail)
+        path = os.fsdecode(os_helper.TESTFN_UNDECODABLE)
+        url = urllib.parse.quote(path, encoding=encoding, errors=errors)
+        self.assertEqual(nturl2path.pathname2url('C:\\' + path),
+                         '///C:/' + url)
 
     @unittest.skipUnless(sys.platform == 'win32',
                          'test specific to Windows pathnames.')
@@ -1730,14 +1733,17 @@ def test_url2pathname_nonascii(self):
         url = urllib.parse.quote(url, encoding=encoding, errors=errors)
         self.assertEqual(urllib.request.url2pathname(url), 
os_helper.FS_NONASCII)
 
+    @unittest.skipUnless(os_helper.TESTFN_UNDECODABLE,
+                         'need os_helper.TESTFN_UNDECODABLE')
     def test_url2pathname_surrogates(self):
         # gh-156713: the filesystem encoding and error handler are used, so
         # that URLs containing percent-encoded surrogates can be converted.
         encoding = sys.getfilesystemencoding()
         errors = sys.getfilesystemencodeerrors()
-        url = urllib.parse.quote('a\udcff', encoding=encoding, errors=errors)
+        path = os.fsdecode(os_helper.TESTFN_UNDECODABLE)
+        url = urllib.parse.quote(path, encoding=encoding, errors=errors)
         self.assertEqual(nturl2path.url2pathname('///C:/' + url),
-                         'C:\\a\udcff')
+                         'C:\\' + path)
 
 class Utility_Tests(unittest.TestCase):
     """Testcase to test the various utility functions in the urllib."""

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to