fix how int filter handles scientific notation (#1984)

This commit is contained in:
David Lord 2024-12-19 07:59:45 -08:00 committed by GitHub
commit 3ef3ba885b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -196,6 +196,7 @@ class TestFilter:
("abc", "0"),
("32.32", "32"),
("12345678901234567890", "12345678901234567890"),
("1e10000", "0"),
),
)
def test_int(self, env, value, expect):