From: Armin Ronacher Date: Thu, 4 Jul 2013 14:25:04 +0000 (+0200) Subject: Fixed a bug with call_filter not working properly X-Git-Tag: 2.7.1~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=342e88a6c43276e4e5c7e8fd9a83c9f6fee4d6b2;p=thirdparty%2Fjinja.git Fixed a bug with call_filter not working properly --- diff --git a/CHANGES b/CHANGES index 3dd68942..839abe74 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,8 @@ Version 2.7.1 ------------- (bugfix release) +- Fixed a bug with ``call_filter`` not working properly on environment + and context filters. Version 2.7 ----------- diff --git a/jinja2/environment.py b/jinja2/environment.py index fad5e237..45fabada 100644 --- a/jinja2/environment.py +++ b/jinja2/environment.py @@ -411,7 +411,7 @@ class Environment(object): func = self.filters.get(name) if func is None: raise TemplateRuntimeError('no filter named %r' % name) - args = list(args or ()) + args = [value] + list(args or ()) if getattr(func, 'contextfilter', False): if context is None: raise TemplateRuntimeError('Attempted to invoke context ' @@ -426,7 +426,7 @@ class Environment(object): args.insert(0, eval_ctx) elif getattr(func, 'environmentfilter', False): args.insert(0, self) - return func(value, *args, **(kwargs or {})) + return func(*args, **(kwargs or {})) def call_test(self, name, value, args=None, kwargs=None): """Invokes a test on a value the same way the compiler does it. diff --git a/jinja2/testsuite/filters.py b/jinja2/testsuite/filters.py index 5219f767..1e1706fd 100644 --- a/jinja2/testsuite/filters.py +++ b/jinja2/testsuite/filters.py @@ -19,6 +19,10 @@ env = Environment() class FilterTestCase(JinjaTestCase): + def test_filter_calling(self): + rv = env.call_filter('sum', [1, 2, 3]) + self.assert_equal(rv, 6) + def test_capitalize(self): tmpl = env.from_string('{{ "foo bar"|capitalize }}') assert tmpl.render() == 'Foo bar'