mirror of https://github.com/python/cpython
gh-117503: Fix support of non-ASCII user names in posixpath.expanduser() (GH-117504)
They are now supported in bytes paths as well as in string paths.
This commit is contained in:
parent
44890b209e
commit
51132da0c4
|
@ -262,7 +262,7 @@ def expanduser(path):
|
|||
return path
|
||||
name = path[1:i]
|
||||
if isinstance(name, bytes):
|
||||
name = name.decode('ascii')
|
||||
name = os.fsdecode(name)
|
||||
try:
|
||||
pwent = pwd.getpwnam(name)
|
||||
except KeyError:
|
||||
|
|
|
@ -344,6 +344,17 @@ class PosixPathTest(unittest.TestCase):
|
|||
for path in ('~', '~/.local', '~vstinner/'):
|
||||
self.assertEqual(posixpath.expanduser(path), path)
|
||||
|
||||
@unittest.skipIf(sys.platform == "vxworks",
|
||||
"no home directory on VxWorks")
|
||||
def test_expanduser_pwd2(self):
|
||||
pwd = import_helper.import_module('pwd')
|
||||
for e in pwd.getpwall():
|
||||
name = e.pw_name
|
||||
home = e.pw_dir
|
||||
self.assertEqual(posixpath.expanduser('~' + name), home)
|
||||
self.assertEqual(posixpath.expanduser(os.fsencode('~' + name)),
|
||||
os.fsencode(home))
|
||||
|
||||
NORMPATH_CASES = [
|
||||
("", "."),
|
||||
("/", "/"),
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix support of non-ASCII user names in bytes paths in
|
||||
:func:`os.path.expanduser` on Posix.
|
Loading…
Reference in New Issue