From: Armin Ronacher Date: Sat, 7 Jan 2017 01:44:37 +0000 (+0100) Subject: Smaller fixes to stuff that broke on 3.x X-Git-Tag: 2.9~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01d9e7e906386d24ef3d067bee40401a138098e6;p=thirdparty%2Fjinja.git Smaller fixes to stuff that broke on 3.x --- diff --git a/jinja2/asyncfilters.py b/jinja2/asyncfilters.py index d12afaf4..5c1f46d7 100644 --- a/jinja2/asyncfilters.py +++ b/jinja2/asyncfilters.py @@ -47,6 +47,8 @@ def dualfilter(normal_filter, async_filter): if wrap_evalctx: wrapper.evalcontextfilter = True + wrapper.asyncfiltervariant = True + return wrapper diff --git a/jinja2/nodes.py b/jinja2/nodes.py index 76f7814c..4d62cccb 100644 --- a/jinja2/nodes.py +++ b/jinja2/nodes.py @@ -592,6 +592,13 @@ class Filter(Expr): filter_ = self.environment.filters.get(self.name) if filter_ is None or getattr(filter_, 'contextfilter', False): raise Impossible() + + # We cannot constant handle async filters, so we need to make sure + # to not go down this path. + if eval_ctx.environment.is_async and \ + getattr(filter_, 'asyncfiltervariant', False): + raise Impossible() + obj = self.node.as_const(eval_ctx) args = [obj] + [x.as_const(eval_ctx) for x in self.args] if getattr(filter_, 'evalcontextfilter', False): diff --git a/tests/test_filters.py b/tests/test_filters.py index 1a8a1640..2e85a9a5 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -581,7 +581,7 @@ class TestFilter(object): env = Environment(autoescape=True) t = env.from_string('{{ x|tojson }}') assert t.render(x={'foo': 'bar'}) == '{"foo": "bar"}' - assert t.render(x='"bar\'') == '"\"bar\u0027"' + assert t.render(x='"bar\'') == r'"\"bar\u0027"' def my_dumps(value, **options): assert options == {'foo': 'bar'}