Skip to content
Myr

Merge branch '2.8-maintenance' of github.com:pallets/jinja into 2.8-maintenance

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

authored by Armin Ronacher · committed by Armin Ronacher · parents 002edca, 368e1b1 · Browse files · 3 files+13 added−4 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+13 added−4 removed

  • tests:+8 added−3 removed
  • other:+5 added−1 removed

3 files+13 added−4 removed

modified:jinja2/filters.py+4 added-1 removed
516 unmodified lines
517 override this default using the first parameter. You518 can also override the default base (10) in the second519 parameter, which handles input with prefixes such as520 0b, 0o and 0x for bases 2, 8 and 16 respectively.521 The base is ignored for decimal numbers and non-string values.522 """523 try:524 if isinstance(value, string_types):523 return int(value, base)525 return int(value, base)526 return int(value)527 except (TypeError, ValueError):528 # this quirk is necessary so that "42.23"|int gives 42.529 try:530 return int(float(value))
469 unmodified lines
modified:tests/test_filters.py+8 added-3 removed
131 unmodified lines
132 assert out == ('foo bar foo bar\n foo bar foo bar| '133 'foo bar foo bar\n foo bar foo bar')134135 def test_int(self, env):136 class IntIsh(object):137 def __int__(self):138 return 42139140 tmpl = env.from_string('{{ "42"|int }}|{{ "ajsghasjgd"|int }}|'141 '{{ "32.32"|int }}|{{ "0x4d32"|int(0, 16) }}|'138 '{{ "011"|int(0, 8)}}|{{ "0x33FU"|int(0, 16) }}')139 out = tmpl.render()140 assert out == '42|0|32|19762|9|0'142 '{{ "011"|int(0, 8)}}|{{ "0x33FU"|int(0, 16) }}|'143 '{{ obj|int }}')144 out = tmpl.render(obj=IntIsh())145 assert out == '42|0|32|19762|9|0|42'146147 def test_join(self, env):148 tmpl = env.from_string('{{ [1, 2, 3]|join("|") }}')149 out = tmpl.render()
414 unmodified lines
modified:CHANGES+1 added
5 unmodified lines
67(bugfix release, released on December 29th 2016)89- Fixed the `for_qs` flag for `urlencode`.10- Fixed regression when applying `int` to non-string values.11- SECURITY: if the sandbox mode is used format expressions are now sandboxed12 with the same rules as in Jinja. This solves various information leakage13 problems that can occur with format strings.14
365 unmodified lines