From ac8b47c8b4edd59aaee857717d434df52ec49e6c Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 5 Dec 2018 23:23:06 +0200 Subject: [PATCH] bpo-34604: Use %R because of invisible characters or trailing whitespaces. (GH-9165). (GH-10947) (cherry picked from commit 34c7f0c04e2b4e715b2c3df1875af8939fbe7d0b) Co-authored-by: William Grzybowski --- .../next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst | 3 +++ Modules/grpmodule.c | 2 +- Modules/pwdmodule.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst diff --git a/Misc/NEWS.d/next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst b/Misc/NEWS.d/next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst new file mode 100644 index 000000000000..958b74fd0da6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst @@ -0,0 +1,3 @@ +Fix possible mojibake in the error message of `pwd.getpwnam` and +`grp.getgrnam` using string representation because of invisible characters +or trailing whitespaces. Patch by William Grzybowski. diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c index 43e45ef7aad5..8a724b6b438f 100644 --- a/Modules/grpmodule.c +++ b/Modules/grpmodule.c @@ -156,7 +156,7 @@ grp_getgrnam_impl(PyObject *module, PyObject *name) goto out; if ((p = getgrnam(name_chars)) == NULL) { - PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %S", name); + PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %R", name); goto out; } retval = mkgrent(p); diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c index 21c2b546f6dd..810427a229b7 100644 --- a/Modules/pwdmodule.c +++ b/Modules/pwdmodule.c @@ -163,7 +163,7 @@ pwd_getpwnam_impl(PyObject *module, PyObject *arg) goto out; if ((p = getpwnam(name)) == NULL) { PyErr_Format(PyExc_KeyError, - "getpwnam(): name not found: %S", arg); + "getpwnam(): name not found: %R", arg); goto out; } retval = mkpwent(p); -- 2.47.3