Skip to content
Myr

use soft_str in do_wordcount, to trigger undefined

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Matt Martz · committed by David Lord · parent 2a70ef2 · Browse files · 3 files+10 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+10 added−2 removed

  • tests:+7 added−0 removed
  • other:+3 added−2 removed

3 files+10 added−2 removed

modified:src/jinja2/filters.py+1 added-1 removed
759 unmodified lines
760761762def do_wordcount(s):763 """Count the words in that string."""764 return len(_word_re.findall(s))764 return len(_word_re.findall(soft_unicode(s)))765766767def do_int(value, default=0, base=10):768 """Convert the value into an integer. If the
614 unmodified lines
modified:tests/test_filters.py+7 added
4 unmodified lines
5import pytest67from jinja2 import Environment8from jinja2 import Markup9from jinja2 import StrictUndefined10from jinja2 import UndefinedError11from jinja2._compat import implements_to_string12from jinja2._compat import text_type1314
355 unmodified lines
370 def test_wordcount(self, env):371 tmpl = env.from_string('{{ "foo bar baz"|wordcount }}')372 assert tmpl.render() == "3"373374 strict_env = Environment(undefined=StrictUndefined)375 t = strict_env.from_string("{{ s|wordcount }}")376 with pytest.raises(UndefinedError):377 t.render()378379 def test_block(self, env):380 tmpl = env.from_string("{% filter lower|escape %}<HEHE>{% endfilter %}")381 assert tmpl.render() == "&lt;hehe&gt;"382
369 unmodified lines
modified:CHANGES.rst+2 added-1 removed
6 unmodified lines
78- Fix a bug that caused callable objects with ``__getattr__``, like9 :class:`~unittest.mock.Mock` to be treated as a10 :func:`contextfunction`. :issue:`1145`11- Update ``wordcount`` filter to trigger :class:`Undefined` methods12 by wrapping the input in :func:`soft_unicode`. :pr:`1160`13141315Version 2.11.116--------------1718Released 2020-01-30
735 unmodified lines