1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #18393 -- Prevented blocktrans to crash when a variable name is badly formatted.

This commit is contained in:
Julien Phalip
2012-05-28 11:03:34 -07:00
parent a535040bfa
commit 432339a72c
4 changed files with 22 additions and 2 deletions

View File

@@ -270,10 +270,11 @@ class TranslationTests(TestCase):
self.assertEqual(to_language('sr_Lat'), 'sr-lat')
@override_settings(LOCALE_PATHS=(os.path.join(here, 'other', 'locale'),))
def test_bad_placeholder(self):
def test_bad_placeholder_1(self):
"""
Error in translation file should not crash template rendering
(%(person)s is translated as %(personne)s in fr.po)
Refs #16516.
"""
from django.template import Template, Context
with translation.override('fr'):
@@ -281,6 +282,19 @@ class TranslationTests(TestCase):
rendered = t.render(Context({'person': 'James'}))
self.assertEqual(rendered, 'My name is James.')
@override_settings(LOCALE_PATHS=(os.path.join(here, 'other', 'locale'),))
def test_bad_placeholder_2(self):
"""
Error in translation file should not crash template rendering
(%(person) misses a 's' in fr.po, causing the string formatting to fail)
Refs #18393.
"""
from django.template import Template, Context
with translation.override('fr'):
t = Template('{% load i18n %}{% blocktrans %}My other name is {{ person }}.{% endblocktrans %}')
rendered = t.render(Context({'person': 'James'}))
self.assertEqual(rendered, 'My other name is James.')
class FormattingTests(TestCase):