Skip to content

Commit cb173bb

Browse files
committed
[4.2.x] Fixed #35172 -- Fixed intcomma for string floats.
Thanks Warwick Brown for the report. Regression in 55519d6. Backport of 2f14c2c from main.
1 parent 227ef29 commit cb173bb

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

django/contrib/humanize/templatetags/humanize.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ def intcomma(value, use_l10n=True):
8080
if match:
8181
prefix = match[0]
8282
prefix_with_commas = re.sub(r"\d{3}", r"\g<0>,", prefix[::-1])[::-1]
83+
# Remove a leading comma, if needed.
84+
prefix_with_commas = re.sub(r"^(-?),", r"\1", prefix_with_commas)
8385
result = prefix_with_commas + result[len(prefix) :]
8486
return result
8587

docs/releases/3.2.25.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
===========================
2+
Django 3.2.25 release notes
3+
===========================
4+
5+
*Expected March 4, 2024*
6+
7+
Django 3.2.25 fixes a regression in 3.2.24.
8+
9+
Bugfixes
10+
========
11+
12+
* Fixed a regression in Django 3.2.24 where ``intcomma`` template filter could
13+
return a leading comma for string representation of floats (:ticket:`35172`).

docs/releases/4.2.11.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
===========================
2+
Django 4.2.11 release notes
3+
===========================
4+
5+
*Expected March 4, 2024*
6+
7+
Django 4.2.11 fixes a regression in 4.2.10.
8+
9+
Bugfixes
10+
========
11+
12+
* Fixed a regression in Django 4.2.10 where ``intcomma`` template filter could
13+
return a leading comma for string representation of floats (:ticket:`35172`).

docs/releases/index.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ versions of the documentation contain the release notes for any later releases.
2626
.. toctree::
2727
:maxdepth: 1
2828

29+
4.2.11
2930
4.2.10
3031
4.2.9
3132
4.2.8
@@ -80,6 +81,7 @@ versions of the documentation contain the release notes for any later releases.
8081
.. toctree::
8182
:maxdepth: 1
8283

84+
3.2.25
8385
3.2.24
8486
3.2.23
8587
3.2.22

tests/humanize_tests/tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,18 @@ def test_intcomma(self):
129129
-1234567.25,
130130
"100",
131131
"-100",
132+
"100.1",
133+
"-100.1",
134+
"100.13",
135+
"-100.13",
132136
"1000",
133137
"-1000",
134138
"10123",
135139
"-10123",
136140
"10311",
137141
"-10311",
142+
"100000.13",
143+
"-100000.13",
138144
"1000000",
139145
"-1000000",
140146
"1234567.1234567",
@@ -163,12 +169,18 @@ def test_intcomma(self):
163169
"-1,234,567.25",
164170
"100",
165171
"-100",
172+
"100.1",
173+
"-100.1",
174+
"100.13",
175+
"-100.13",
166176
"1,000",
167177
"-1,000",
168178
"10,123",
169179
"-10,123",
170180
"10,311",
171181
"-10,311",
182+
"100,000.13",
183+
"-100,000.13",
172184
"1,000,000",
173185
"-1,000,000",
174186
"1,234,567.1234567",

0 commit comments

Comments
 (0)