diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
index 78a51cf..ea59bc5 100644
a
|
b
|
def get_system_username():
|
82 | 82 | username could not be determined. |
83 | 83 | """ |
84 | 84 | try: |
85 | | return getpass.getuser().decode(locale.getdefaultlocale()[1]) |
| 85 | system_locale = locale.getdefaultlocale()[1] |
| 86 | if system_locale: |
| 87 | return getpass.getuser().decode(system_locale) |
| 88 | else: |
| 89 | return getpass.getuser().decode(errors='ignore') |
86 | 90 | except (ImportError, KeyError, UnicodeDecodeError): |
87 | 91 | # KeyError will be raised by os.getpwuid() (called by getuser()) |
88 | 92 | # if there is no corresponding entry in the /etc/passwd file |
diff --git a/django/contrib/auth/tests/management.py b/django/contrib/auth/tests/management.py
index 0af6873..afbb748 100644
a
|
b
|
class GetDefaultUsernameTestCase(TestCase):
|
25 | 25 | # 'Julia' with accented 'u': |
26 | 26 | management.get_system_username = lambda: u'J\xfalia' |
27 | 27 | self.assertEqual(management.get_default_username(), 'julia') |
| 28 | |
| 29 | def test_locale_empty(self): |
| 30 | # Test for emty locale. |
| 31 | import locale |
| 32 | import getpass |
| 33 | locale.getdefaultlocale = lambda: (None,None) |
| 34 | getpass.getuser = lambda: 'J\xfalia' |
| 35 | self.assertEqual(management.get_system_username(), u'Jlia') |