Skip to content

Commit fffa64a

Browse files
varunkasyappjacobtylerwalls
authored andcommitted
Fixed #36715 -- Handled non-finite Decimals in intcomma filter.
1 parent e78420c commit fffa64a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

django/utils/numberformat.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def format(
4848
if abs(number) < cutoff:
4949
number = Decimal("0")
5050

51+
if not number.is_finite():
52+
return str(number)
53+
5154
# Format values with more than 200 digits (an arbitrary cutoff) using
5255
# scientific notation to avoid high memory usage in {:f}'.format().
5356
_, digits, exponent = number.as_tuple()

tests/humanize_tests/tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ def test_intcomma(self):
153153
"-1234567.1234567",
154154
Decimal("1234567.1234567"),
155155
Decimal("-1234567.1234567"),
156+
Decimal("Infinity"),
157+
Decimal("-Infinity"),
158+
Decimal("NaN"),
156159
None,
157160
"1234567",
158161
"-1234567",
@@ -193,6 +196,9 @@ def test_intcomma(self):
193196
"-1,234,567.1234567",
194197
"1,234,567.1234567",
195198
"-1,234,567.1234567",
199+
"Infinity",
200+
"-Infinity",
201+
"NaN",
196202
None,
197203
"1,234,567",
198204
"-1,234,567",

0 commit comments

Comments
 (0)