From 052e2203160e0e0052024775653ebb78bc76eb28 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonas=20Borgstr=C3=B6m?= Date: Thu, 13 Jun 2013 22:17:32 +0200 Subject: [PATCH] Use "surrogateescape" error handler when encoding unicode paths. On Python 3 functions like os.listdir() always returns unicode paths. "invalid" byte paths are decoded using the "surrogateescape" error handler which must also be used when decoding. See os.fsencodefs() and os.fsdecode(). --- xattr.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xattr.c b/xattr.c index 57257bb..f3660b0 100644 --- a/xattr.c +++ b/xattr.c @@ -147,7 +147,13 @@ static int convert_obj(PyObject *myobj, target_t *tgt, int nofollow) { tgt->type = nofollow ? T_LINK : T_PATH; tgt->tmp = \ PyUnicode_AsEncodedString(myobj, - Py_FileSystemDefaultEncoding, "strict"); + Py_FileSystemDefaultEncoding, +#ifdef IS_PY3K + "surrogateescape" +#else + "strict" +#endif + ); if(tgt->tmp == NULL) return -1; tgt->name = PyBytes_AS_STRING(tgt->tmp); -- 2.39.5