From 342e88a6c43276e4e5c7e8fd9a83c9f6fee4d6b2 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Thu, 4 Jul 2013 16:25:04 +0200 Subject: Fixed a bug with call_filter not working properly --- CHANGES | 2 ++ jinja2/environment.py | 4 ++-- jinja2/testsuite/filters.py | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 3dd6894..839abe7 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 fad5e23..45fabad 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 5219f76..1e1706f 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' -- cgit v1.2.1