From: Armin Ronacher Date: Tue, 6 Jul 2010 09:37:45 +0000 (+0200) Subject: Added new testcase X-Git-Tag: 2.5.1~9 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4cccc222625748a6f9f19d266958023d4df02271;p=jinja2.git Added new testcase --HG-- branch : trunk --- diff --git a/jinja2/ext.py b/jinja2/ext.py index ddab4fb..ceb3895 100644 --- a/jinja2/ext.py +++ b/jinja2/ext.py @@ -327,7 +327,7 @@ class InternationalizationExtension(Extension): 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: diff --git a/jinja2/testsuite/ext.py b/jinja2/testsuite/ext.py index 6a88834..530fed4 100644 --- a/jinja2/testsuite/ext.py +++ b/jinja2/testsuite/ext.py @@ -54,7 +54,9 @@ newstyle_i18n_templates = { '{{ 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 @@ class NewstyleInternationalizationTestCase(JinjaTestCase): 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):