FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-156713: Fix test_nturl2path for non-UTF-8 filesystem encodings (GH-157461) by miss-islington · Pull Request #157462 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
32 changes: 25 additions & 7 deletions Lib/test/test_nturl2path.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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__':
Expand Down
Loading

Back | FazBrowse Home | New Git URL