diff --git a/src/windows/common/wslutil.cpp b/src/windows/common/wslutil.cpp index aeca79266..8d2136185 100644 --- a/src/windows/common/wslutil.cpp +++ b/src/windows/common/wslutil.cpp @@ -1363,8 +1363,15 @@ void wsl::windows::common::wslutil::SetCrtEncoding(int Mode) setMode(stdout, Mode); setMode(stderr, Mode); - // Set the locale to the current environment's default locale. + // Set the locale to the current environment's default locale for regional + // formatting (numeric, time, collation), then override LC_CTYPE to UTF-8 + // so that narrow-to-wide conversions (e.g. %hs in wprintf) correctly decode + // UTF-8 multi-byte sequences from Linux/container processes. WI_VERIFY(_wsetlocale(LC_ALL, L"") != NULL); + if (Mode == _O_U8TEXT) + { + WI_VERIFY(_wsetlocale(LC_CTYPE, L".UTF-8") != NULL); + } } void wsl::windows::common::wslutil::SetThreadDescription(LPCWSTR Name)