Skip to content

Commit

Permalink
fix how int filter handles scientific notation (#1984)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Dec 19, 2024
2 parents 20be10e + 2eb4542 commit 3ef3ba8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Unreleased
when calling block references. :issue:`1701`
- Make ``|unique`` async-aware, allowing it to be used after another
async-aware filter. :issue:`1781`
- ``|int`` filter handles ``OverflowError`` from scientific notation.
:issue:`1921`


Version 3.1.4
Expand Down
2 changes: 1 addition & 1 deletion src/jinja2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ def do_int(value: t.Any, default: int = 0, base: int = 10) -> int:
# this quirk is necessary so that "42.23"|int gives 42.
try:
return int(float(value))
except (TypeError, ValueError):
except (TypeError, ValueError, OverflowError):
return default


Expand Down
1 change: 1 addition & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def test_indent_width_string(self, env):
("abc", "0"),
("32.32", "32"),
("12345678901234567890", "12345678901234567890"),
("1e10000", "0"),
),
)
def test_int(self, env, value, expect):
Expand Down

0 comments on commit 3ef3ba8

Please sign in to comment.