]> granicus.if.org Git - python/commitdiff
Fix for issue 6393: Python crashes on OSX when $LANG is set to some (but
authorRonald Oussoren <ronaldoussoren@mac.com>
Sun, 6 Sep 2009 13:59:02 +0000 (13:59 +0000)
committerRonald Oussoren <ronaldoussoren@mac.com>
Sun, 6 Sep 2009 13:59:02 +0000 (13:59 +0000)
not all) invalid values due to an invalid result from nl_langinfo

Lib/locale.py

index 4ab3c6a48c351fb7ce48010ac9a45a207f9f8d92..b7aaa52f041990ebee8356566727274130cf8ff9 100644 (file)
@@ -570,10 +570,22 @@ else:
                 except Error:
                     pass
                 result = nl_langinfo(CODESET)
+                if not result and sys.platform == 'darwin':
+                    # nl_langinfo can return an empty string
+                    # when the setting has an invalid value.
+                    # Default to UTF-8 in that case because
+                    # UTF-8 is the default charset on OSX and
+                    # returning nothing will crash the
+                    # interpreter.
+                    result = 'UTF-8'
+
                 setlocale(LC_CTYPE, oldloc)
                 return result
             else:
-                return nl_langinfo(CODESET)
+                result = nl_langinfo(CODESET)
+                if not result and sys.platform == 'darwin':
+                    # See above for explanation
+                    result = 'UTF-8'
 
 
 ### Database