[3.7] bpo-34604: Fix possible mojibake in pwd.getpwnam() and grp.getgrnam() (GH-9098) (GH-9104)
Pass the user/group name as Unicode to the formatting function,
instead of always decoding a bytes string from UTF-8..
(cherry picked from commit 28658485a54ad5f9df52ecc12d9046269f1654ec)
Co-authored-by: William Grzybowski <wg@FreeBSD.org>
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index bbef2de..21c2b54 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -163,7 +163,7 @@
goto out;
if ((p = getpwnam(name)) == NULL) {
PyErr_Format(PyExc_KeyError,
- "getpwnam(): name not found: %s", name);
+ "getpwnam(): name not found: %S", arg);
goto out;
}
retval = mkpwent(p);