From c5989cd87659acbfd4d19dc00dbe99c3a0fc9bd2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 29 Aug 2018 19:32:47 +0200 Subject: bpo-34523: Py_DecodeLocale() use UTF-8 on Windows (GH-8998) Py_DecodeLocale() and Py_EncodeLocale() now use the UTF-8 encoding on Windows if Py_LegacyWindowsFSEncodingFlag is zero. pymain_read_conf() now sets Py_LegacyWindowsFSEncodingFlag in its loop, but restore its value at exit. --- Python/fileutils.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Python') diff --git a/Python/fileutils.c b/Python/fileutils.c index e756c260cd..9a3c334d43 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -499,9 +499,13 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen, return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason, surrogateescape); #else - if (Py_UTF8Mode == 1) { - return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason, - surrogateescape); + int use_utf8 = (Py_UTF8Mode == 1); +#ifdef MS_WINDOWS + use_utf8 |= !Py_LegacyWindowsFSEncodingFlag; +#endif + if (use_utf8) { + return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, + reason, surrogateescape); } #ifdef USE_FORCE_ASCII @@ -661,7 +665,11 @@ encode_locale_ex(const wchar_t *text, char **str, size_t *error_pos, return _Py_EncodeUTF8Ex(text, str, error_pos, reason, raw_malloc, surrogateescape); #else /* __APPLE__ */ - if (Py_UTF8Mode == 1) { + int use_utf8 = (Py_UTF8Mode == 1); +#ifdef MS_WINDOWS + use_utf8 |= !Py_LegacyWindowsFSEncodingFlag; +#endif + if (use_utf8) { return _Py_EncodeUTF8Ex(text, str, error_pos, reason, raw_malloc, surrogateescape); } -- cgit v1.2.1