Skip to content

Commit 1dfd6d5

Browse files
[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 fd0970c)
1 parent c27500b commit 1dfd6d5

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

Lib/test/test_urllib.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,14 +1660,17 @@ def test_pathname2url_nonascii(self):
16601660
url = urllib.parse.quote(os_helper.FS_NONASCII, encoding=encoding, errors=errors)
16611661
self.assertEqual(urllib.request.pathname2url(os_helper.FS_NONASCII), url)
16621662

1663+
@unittest.skipUnless(os_helper.TESTFN_UNDECODABLE,
1664+
'need os_helper.TESTFN_UNDECODABLE')
16631665
def test_pathname2url_surrogates(self):
16641666
# gh-156713: the filesystem encoding and error handler are used,
16651667
# so that paths containing surrogate characters can be converted.
16661668
encoding = sys.getfilesystemencoding()
16671669
errors = sys.getfilesystemencodeerrors()
1668-
tail = urllib.parse.quote('a\udcff', encoding=encoding, errors=errors)
1669-
self.assertEqual(nturl2path.pathname2url('C:\\a\udcff'),
1670-
'///C:/' + tail)
1670+
path = os.fsdecode(os_helper.TESTFN_UNDECODABLE)
1671+
url = urllib.parse.quote(path, encoding=encoding, errors=errors)
1672+
self.assertEqual(nturl2path.pathname2url('C:\\' + path),
1673+
'///C:/' + url)
16711674

16721675
@unittest.skipUnless(sys.platform == 'win32',
16731676
'test specific to Windows pathnames.')
@@ -1730,14 +1733,17 @@ def test_url2pathname_nonascii(self):
17301733
url = urllib.parse.quote(url, encoding=encoding, errors=errors)
17311734
self.assertEqual(urllib.request.url2pathname(url), os_helper.FS_NONASCII)
17321735

1736+
@unittest.skipUnless(os_helper.TESTFN_UNDECODABLE,
1737+
'need os_helper.TESTFN_UNDECODABLE')
17331738
def test_url2pathname_surrogates(self):
17341739
# gh-156713: the filesystem encoding and error handler are used, so
17351740
# that URLs containing percent-encoded surrogates can be converted.
17361741
encoding = sys.getfilesystemencoding()
17371742
errors = sys.getfilesystemencodeerrors()
1738-
url = urllib.parse.quote('a\udcff', encoding=encoding, errors=errors)
1743+
path = os.fsdecode(os_helper.TESTFN_UNDECODABLE)
1744+
url = urllib.parse.quote(path, encoding=encoding, errors=errors)
17391745
self.assertEqual(nturl2path.url2pathname('///C:/' + url),
1740-
'C:\\a\udcff')
1746+
'C:\\' + path)
17411747

17421748
class Utility_Tests(unittest.TestCase):
17431749
"""Testcase to test the various utility functions in the urllib."""

0 commit comments

Comments
 (0)