add changelog and test

This commit is contained in:
David Lord 2020-02-04 08:46:53 -08:00
parent 9933324688
commit 04294999c7
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
2 changed files with 31 additions and 1 deletions

View File

@ -1,9 +1,20 @@
.. currentmodule:: jinja2
2.11.2
------
Unreleased
- Fix a bug that caused callable objects with ``__getattr__``, like
:class:`~unittest.mock.Mock` to be treated as a
:func:`contextfunction`. :issue:`1145`
Version 2.11.1
--------------
Unreleased
Released 2020-01-30
- Fix a bug that prevented looking up a key after an attribute
(``{{ data.items[1:] }}``) in an async template. :issue:`1141`

View File

@ -54,3 +54,22 @@ def test_iterator_not_advanced_early():
# groupby groups depend on the current position of the iterator. If
# it was advanced early, the lists would appear empty.
assert out == "1 [(1, 'a'), (1, 'b')]\n2 [(2, 'c')]\n3 [(3, 'd')]\n"
def test_mock_not_contextfunction():
"""If a callable class has a ``__getattr__`` that returns True-like
values for arbitrary attrs, it should not be incorrectly identified
as a ``contextfunction``.
"""
class Calc(object):
def __getattr__(self, item):
return object()
def __call__(self, *args, **kwargs):
return len(args) + len(kwargs)
t = Template("{{ calc() }}")
out = t.render(calc=Calc())
# Would be "1" if context argument was passed.
assert out == "0"