Skip to content

Commit

Permalink
Ensure cocoa_get_lang() returns a valid locale or None
Browse files Browse the repository at this point in the history
See #1233
  • Loading branch information
kovidgoyal committed Jun 18, 2020
1 parent deb564e commit e96dfad
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion kitty/cocoa_window.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// Needed for _NSGetProgname
#include <crt_externs.h>
#include <objc/runtime.h>
#include <xlocale.h>

#if (MAC_OS_X_VERSION_MAX_ALLOWED < 101200)
#define NSWindowStyleMaskResizable NSResizableWindowMask
Expand Down Expand Up @@ -419,7 +420,13 @@ - (void)openFilesFromPasteboard:(NSPasteboard *)pasteboard type:(int)type {
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
}
Expand Down

0 comments on commit e96dfad

Please sign in to comment.