https://github.com/python/cpython/commit/96b29b32c181716d1b6b62976e241b8c74b77430
commit: 96b29b32c181716d1b6b62976e241b8c74b77430
branch: 3.12
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-04-17T10:43:37Z
summary:
[3.12] gh-117503: Fix support of non-ASCII user names in posixpath.expanduser()
(GH-117504) (GH-117970)
They are now supported in bytes paths as well as in string paths.
(cherry picked from commit 51132da0c4dac13500d9bb86b2fdad42091d3fd9)
files:
A Misc/NEWS.d/next/Library/2024-04-03-15-04-23.gh-issue-117503.NMfwup.rst
M Lib/posixpath.py
M Lib/test/test_posixpath.py
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index e4f155e41a3221..bd81c09bb2bdd0 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -290,7 +290,7 @@ def expanduser(path):
return path
name = path[1:i]
if isinstance(name, bytes):
- name = str(name, 'ASCII')
+ name = os.fsdecode(name)
try:
pwent = pwd.getpwnam(name)
except KeyError:
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index 9be4640f970aef..ddc097548542fc 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -334,6 +334,17 @@ def test_expanduser_pwd(self):
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 = [
("", "."),
("/", "/"),
diff --git
a/Misc/NEWS.d/next/Library/2024-04-03-15-04-23.gh-issue-117503.NMfwup.rst
b/Misc/NEWS.d/next/Library/2024-04-03-15-04-23.gh-issue-117503.NMfwup.rst
new file mode 100644
index 00000000000000..f0ea513ac9d4a9
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-04-03-15-04-23.gh-issue-117503.NMfwup.rst
@@ -0,0 +1,2 @@
+Fix support of non-ASCII user names in bytes paths in
+:func:`os.path.expanduser` on Posix.
_______________________________________________
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]