fix how int filter handles scientific notation (#1984)
This commit is contained in:
commit
3ef3ba885b
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
@ -196,6 +196,7 @@ class TestFilter:
|
||||
("abc", "0"),
|
||||
("32.32", "32"),
|
||||
("12345678901234567890", "12345678901234567890"),
|
||||
("1e10000", "0"),
|
||||
),
|
||||
)
|
||||
def test_int(self, env, value, expect):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user