https://github.com/python/cpython/commit/0ad0330ba6602091e42a0252bd4c9a7f1eb93b02
commit: 0ad0330ba6602091e42a0252bd4c9a7f1eb93b02
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-09-13T21:11:19Z
summary:

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

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

Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>

files:
M Lib/test/test_nturl2path.py

diff --git a/Lib/test/test_nturl2path.py b/Lib/test/test_nturl2path.py
index b4532137968d6e..56e47aef5fe4c5 100644
--- a/Lib/test/test_nturl2path.py
+++ b/Lib/test/test_nturl2path.py
@@ -1,7 +1,9 @@
+import os
 import sys
 import unittest
 import urllib.parse
 
+from test.support import os_helper
 from test.support import warnings_helper
 
 
@@ -36,7 +38,6 @@ def test_pathname2url(self):
         self.assertEqual(fn('C:\\a\\b.c\\'), '///C:/a/b.c/')
         self.assertEqual(fn('C:\\a\\\\b.c'), '///C:/a//b.c')
         self.assertEqual(fn('C:\\a\\b%#c'), '///C:/a/b%25%23c')
-        self.assertEqual(fn('C:\\a\\b\xe9'), '///C:/a/b%C3%A9')
         self.assertEqual(fn('C:\\foo\\bar\\spam.foo'), 
"///C:/foo/bar/spam.foo")
         # NTFS alternate data streams
         self.assertEqual(fn('C:\\foo:bar'), '///C:/foo%3Abar')
@@ -47,7 +48,7 @@ def test_pathname2url(self):
         self.assertEqual(fn("\\\\\\folder\\test\\"), '///folder/test/')
         self.assertEqual(fn('\\\\some\\share\\'), '//some/share/')
         self.assertEqual(fn('\\\\some\\share\\a\\b.c'), '//some/share/a/b.c')
-        self.assertEqual(fn('\\\\some\\share\\a\\b%#c\xe9'), 
'//some/share/a/b%25%23c%C3%A9')
+        self.assertEqual(fn('\\\\some\\share\\a\\b%#c'), 
'//some/share/a/b%25%23c')
         # Alternate path separator
         self.assertEqual(fn('C:/a/b.c'), '///C:/a/b.c')
         self.assertEqual(fn('//some/share/a/b.c'), '//some/share/a/b.c')
@@ -60,14 +61,28 @@ def test_pathname2url(self):
         for url in urls:
             self.assertEqual(fn(nturl2path.url2pathname(url)), url)
 
+    @unittest.skipUnless(os_helper.FS_NONASCII, 'need os_helper.FS_NONASCII')
+    def test_pathname2url_nonascii(self):
+        encoding = sys.getfilesystemencoding()
+        errors = sys.getfilesystemencodeerrors()
+        char = os_helper.FS_NONASCII
+        quoted = urllib.parse.quote(char, encoding=encoding, errors=errors)
+        self.assertEqual(nturl2path.pathname2url(f'C:\\a\\b{char}'),
+                         '///C:/a/b' + quoted)
+        
self.assertEqual(nturl2path.pathname2url(f'\\\\some\\share\\a\\b{char}'),
+                         '//some/share/a/b' + quoted)
+
+    @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)
 
     def test_url2pathname(self):
         fn = nturl2path.url2pathname
@@ -114,14 +129,17 @@ def test_url2pathname(self):
             self.assertEqual(fn(nturl2path.pathname2url(path)), path)
 
 
+    @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)
 
 
 if __name__ == '__main__':

_______________________________________________
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