diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index 867b21cbf..fe7e9640f 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -14,6 +14,7 @@ // Needed for _NSGetProgname #include #include +#include #if (MAC_OS_X_VERSION_MAX_ALLOWED < 101200) #define NSWindowStyleMaskResizable NSResizableWindowMask @@ -419,7 +420,13 @@ cocoa_get_lang(PyObject UNUSED *self) { locale = [[NSLocale currentLocale] localeIdentifier]; } if (!locale) { Py_RETURN_NONE; } - return Py_BuildValue("s", [locale UTF8String]); + // Make sure the locale value is valid, that is it can be used + // to construct an actual locale + const char* locale_utf8 = [locale UTF8String]; + locale_t test_locale = newlocale(LC_ALL_MASK, locale_utf8, NULL); + if (!test_locale) { Py_RETURN_NONE; } + freelocale(test_locale); + return Py_BuildValue("s", locale_utf8); } // autoreleasepool }