diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-11-14 10:50:15 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-11-14 10:55:12 +0100 |
| commit | ebafba50a418d4a444a067a3d35cea7f98a20158 (patch) | |
| tree | a8da9495d322a2392e50b731cf2b526a2496f268 | |
| parent | 8967906e0a38884665cf542dfb2d84b087d23d99 (diff) | |
[1.5.x] Fixed #19272 -- Fixed gettext_lazy returned type on Python 2
Thanks tyrion for the report.
Backport of 550ddc66b from master.
| -rw-r--r-- | django/utils/translation/trans_real.py | 3 | ||||
| -rw-r--r-- | tests/regressiontests/i18n/tests.py | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index 9e94840ee0..1bcef2d8de 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -246,7 +246,8 @@ def do_translate(message, translation_function): """ global _default - eol_message = message.replace('\r\n', '\n').replace('\r', '\n') + # str() is allowing a bytestring message to remain bytestring on Python 2 + eol_message = message.replace(str('\r\n'), str('\n')).replace(str('\r'), str('\n')) t = getattr(_active, "value", None) if t is not None: result = getattr(t, translation_function)(eol_message) diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index 4054f85ef0..2e0c097a19 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -83,6 +83,10 @@ class TranslationTests(TestCase): s4 = ugettext_lazy('Some other string') self.assertEqual(False, s == s4) + if not six.PY3: + # On Python 2, gettext_lazy should not transform a bytestring to unicode + self.assertEqual(gettext_lazy(b"test").upper(), b"TEST") + def test_lazy_pickle(self): s1 = ugettext_lazy("test") self.assertEqual(six.text_type(s1), "test") |
