From 57ad6b59610319380e9aa6883c1010739e1071c3 Mon Sep 17 00:00:00 2001 From: Felipe Moreno Date: Mon, 20 May 2024 11:02:20 -0400 Subject: [PATCH 1/3] added OverflowError to catch edge case --- src/jinja2/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jinja2/filters.py b/src/jinja2/filters.py index acd11976e..66ce95944 100644 --- a/src/jinja2/filters.py +++ b/src/jinja2/filters.py @@ -987,7 +987,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 From 8ca2cb856c8c06c66fee76ae9c0828365b7bafa0 Mon Sep 17 00:00:00 2001 From: Felipe Moreno Date: Mon, 20 May 2024 11:02:43 -0400 Subject: [PATCH 2/3] added a new test case --- tests/test_filters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_filters.py b/tests/test_filters.py index d8e9114d0..2cb53ac9d 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -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): From cc97ac3ab3d32e304cf952de6228a96758280143 Mon Sep 17 00:00:00 2001 From: Felipe Moreno Date: Mon, 20 May 2024 11:13:28 -0400 Subject: [PATCH 3/3] added entry to CHANGES.rst --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 7fb729763..38b32f164 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,8 @@ Unreleased ``Template.generate_async``. :pr:`1960` - Avoid leaving async generators unclosed in blocks, includes and extends. :pr:`1960` +- Added ``OverflowError`` to the list of exceptions caught by the + ``int`` filter. :issue:`1921` Version 3.1.4