Skip to content

Commit e74dc0e

Browse files
author
ronald.oussoren
committed
Merged revisions 74687 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r74687 | ronald.oussoren | 2009-09-06 15:59:02 +0200 (Sun, 06 Sep 2009) | 3 lines Fix for issue 6393: Python crashes on OSX when $LANG is set to some (but not all) invalid values due to an invalid result from nl_langinfo ........ git-svn-id: http://svn.python.org/projects/python/branches/release31-maint@74688 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent ba1016e commit e74dc0e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

Lib/locale.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,22 @@ def getpreferredencoding(do_setlocale = True):
567567
except Error:
568568
pass
569569
result = nl_langinfo(CODESET)
570+
if not result and sys.platform == 'darwin':
571+
# nl_langinfo can return an empty string
572+
# when the setting has an invalid value.
573+
# Default to UTF-8 in that case because
574+
# UTF-8 is the default charset on OSX and
575+
# returning nothing will crash the
576+
# interpreter.
577+
result = 'UTF-8'
578+
570579
setlocale(LC_CTYPE, oldloc)
571580
return result
572581
else:
573-
return nl_langinfo(CODESET)
582+
result = nl_langinfo(CODESET)
583+
if not result and sys.platform == 'darwin':
584+
# See above for explanation
585+
result = 'UTF-8'
574586

575587

576588
### Database

0 commit comments

Comments
 (0)