@@ -869,15 +869,23 @@ TEST(platform_env_long_refuses_what_it_cannot_read) {
869869 * setter must update that same wide environment; _putenv_s alone interprets
870870 * UTF-8 path bytes through the active ANSI code page. */
871871TEST (platform_setenv_preserves_utf8_in_wide_environment ) {
872- static const char utf8 [] = "C:/cbm-cache-\xce\x94-\xe6\x97\xa5\xe6\x9c\xac" ;
873- static const wchar_t wide [] = L"C:/cbm-cache-\u0394-\u65e5\u672c" ;
872+ static const char utf8 [] = "C:/cbm-cache-\xce\x94-\xe6\x97\xa5\xe6\x9c\xac-\xe4\xb8\x81 " ;
873+ static const wchar_t wide [] = L"C:/cbm-cache-\u0394-\u65e5\u672c-\u4e01 " ;
874874 ASSERT_EQ (cbm_setenv ("CBM_CACHE_DIR" , utf8 , 1 ), 0 );
875875 wchar_t observed_wide [128 ];
876876 ASSERT_EQ (GetEnvironmentVariableW (L"CBM_CACHE_DIR" , observed_wide , 128 ), (DWORD )(wcslen (wide )));
877877 ASSERT_EQ (wcscmp (observed_wide , wide ), 0 );
878878 char observed_utf8 [128 ];
879879 ASSERT_NOT_NULL (cbm_safe_getenv ("CBM_CACHE_DIR" , observed_utf8 , sizeof (observed_utf8 ), NULL ));
880880 ASSERT_STR_EQ (observed_utf8 , utf8 );
881+ /* Narrow getenv must agree with the CRT's active ANSI code page. */
882+ char expected_narrow [128 ];
883+ ASSERT_GT (WideCharToMultiByte (CP_ACP , 0 , wide , -1 , expected_narrow ,
884+ (int )sizeof (expected_narrow ), NULL , NULL ),
885+ 0 );
886+ const char * observed_narrow = getenv ("CBM_CACHE_DIR" );
887+ ASSERT_NOT_NULL (observed_narrow );
888+ ASSERT_STR_EQ (observed_narrow , expected_narrow );
881889 (void )cbm_unsetenv ("CBM_CACHE_DIR" );
882890 PASS ();
883891}
0 commit comments