From 4cccc222625748a6f9f19d266958023d4df02271 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 6 Jul 2010 11:37:45 +0200 Subject: [PATCH] Added new testcase --HG-- branch : trunk --- jinja2/ext.py | 2 +- jinja2/testsuite/ext.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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): -- 2.26.2