Skip to content
Myr

fix how int filter handles scientific notation (#1984)

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

authored by David Lord · committed by GitHub · parents 20be10e, 2eb4542 · Browse files · 3 files+4 added−1 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+4 added−1 removed

  • tests:+1 added−0 removed
  • other:+3 added−1 removed

3 files+4 added−1 removed

modified:src/jinja2/filters.py+1 added-1 removed
997 unmodified lines
998 except (TypeError, ValueError):999 # this quirk is necessary so that "42.23"|int gives 42.1000 try:1001 return int(float(value))1002 except (TypeError, ValueError):1002 except (TypeError, ValueError, OverflowError):1003 return default100410051006def do_float(value: t.Any, default: float = 0.0) -> float:
872 unmodified lines
modified:tests/test_filters.py+1 added
194 unmodified lines
195 ("42", "42"),196 ("abc", "0"),197 ("32.32", "32"),198 ("12345678901234567890", "12345678901234567890"),199 ("1e10000", "0"),200 ),201 )202 def test_int(self, env, value, expect):203 t = env.from_string("{{ value|int }}")
680 unmodified lines
modified:CHANGES.rst+2 added
16 unmodified lines
17- The runtime uses the correct ``concat`` function for the current environment18 when calling block references. :issue:`1701`19- Make ``|unique`` async-aware, allowing it to be used after another20 async-aware filter. :issue:`1781`21- ``|int`` filter handles ``OverflowError`` from scientific notation.22 :issue:`1921`232425Version 3.1.426-------------
994 unmodified lines