]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
int filter handles OverflowError to handle scientific notation 1984/head
authorFelipe Moreno <felipe@flpm.dev>
Mon, 20 May 2024 15:02:20 +0000 (11:02 -0400)
committerDavid Lord <davidism@gmail.com>
Thu, 19 Dec 2024 15:58:25 +0000 (07:58 -0800)
CHANGES.rst
src/jinja2/filters.py
tests/test_filters.py

index e4bffbfb91d73599b0ba1626048b3c2c4a9c1cdf..6c998e62692ba6806ed8b44167f221c20d599b2e 100644 (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
index af9f6bc0ee9af03b2e526c4befc4443d0acde4b9..a92832a34063c9ae13845432e407e7db3bf8e261 100644 (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
 
 
index d8e9114d0f61a9158bac32d94c4e2ca31faea065..2cb53ac9d07f0c5e1d860fbd07ce3baade43cfd7 100644 (file)
@@ -196,6 +196,7 @@ class TestFilter:
             ("abc", "0"),
             ("32.32", "32"),
             ("12345678901234567890", "12345678901234567890"),
+            ("1e10000", "0"),
         ),
     )
     def test_int(self, env, value, expect):