Skip to content
Browse files

Added new testcase

--HG--
branch : trunk
  • Loading branch information...
1 parent 4f77a30 commit 4cccc222625748a6f9f19d266958023d4df02271 @mitsuhiko committed
Showing with 10 additions and 2 deletions.
  1. +1 −1 jinja2/ext.py
  2. +9 −1 jinja2/testsuite/ext.py
View
2 jinja2/ext.py
@@ -327,7 +327,7 @@ def _make_node(self, singular, plural, variables, plural_expr,
vars_referenced, num_called_num):
"""Generates a useful node from the data provided."""
# no variables referenced? no need to escape for old style
- # gettext invocations
+ # gettext invocations only if there are vars.
if not vars_referenced and not self.environment.newstyle_gettext:
singular = singular.replace('%%', '%')
if plural:
View
10 jinja2/testsuite/ext.py
@@ -54,7 +54,9 @@
'{{ num }} apples{% endtrans %}',
'transvars1.html': '{% trans %}User: {{ num }}{% endtrans %}',
'transvars2.html': '{% trans num=count %}User: {{ num }}{% endtrans %}',
- 'transvars3.html': '{% trans count=num %}User: {{ count }}{% endtrans %}'
+ 'transvars3.html': '{% trans count=num %}User: {{ count }}{% endtrans %}',
+ 'novars.html': '{% trans %}%(hello)s{% endtrans %}',
+ 'vars.html': '{% trans %}{{ foo }}%(foo)s{% endtrans %}'
}
@@ -357,6 +359,12 @@ def test_trans_vars(self):
assert t2.render(count=23, LANGUAGE='de') == 'Benutzer: 23'
assert t3.render(num=42, LANGUAGE='de') == 'Benutzer: 42'
+ def test_novars_vars_escaping(self):
+ t = newstyle_i18n_env.get_template('novars.html')
+ assert t.render() == '%(hello)s'
+ t = newstyle_i18n_env.get_template('vars.html')
+ assert t.render(foo='42') == '42%(foo)s'
+
class AutoEscapeTestCase(JinjaTestCase):

0 comments on commit 4cccc22

Please sign in to comment.
Something went wrong with that request. Please try again.