Skip to content

Commit

Permalink
[3.2.x] Fixed #35172 -- Fixed intcomma for string floats.
Browse files Browse the repository at this point in the history
Thanks Warwick Brown for the report.

Regression in 55519d6.

Backport of 2f14c2c from main.
  • Loading branch information
felixxm committed Feb 8, 2024
1 parent b9170b4 commit fc41af6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions django/contrib/humanize/templatetags/humanize.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def intcomma(value, use_l10n=True):
if match:
prefix = match[0]
prefix_with_commas = re.sub(r"\d{3}", r"\g<0>,", prefix[::-1])[::-1]
# Remove a leading comma, if needed.
prefix_with_commas = re.sub(r"^(-?),", r"\1", prefix_with_commas)
result = prefix_with_commas + result[len(prefix) :]
return result

Expand Down
13 changes: 13 additions & 0 deletions docs/releases/3.2.25.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
===========================
Django 3.2.25 release notes
===========================

*Expected March 4, 2024*

Django 3.2.25 fixes a regression in 3.2.24.

Bugfixes
========

* Fixed a regression in Django 3.2.24 where ``intcomma`` template filter could
return a leading comma for string representation of floats (:ticket:`35172`).
1 change: 1 addition & 0 deletions docs/releases/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ versions of the documentation contain the release notes for any later releases.
.. toctree::
:maxdepth: 1

3.2.25
3.2.24
3.2.23
3.2.22
Expand Down
12 changes: 12 additions & 0 deletions tests/humanize_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ def test_intcomma(self):
-1234567.25,
"100",
"-100",
"100.1",
"-100.1",
"100.13",
"-100.13",
"1000",
"-1000",
"10123",
"-10123",
"10311",
"-10311",
"100000.13",
"-100000.13",
"1000000",
"-1000000",
"1234567.1234567",
Expand Down Expand Up @@ -114,12 +120,18 @@ def test_intcomma(self):
"-1,234,567.25",
"100",
"-100",
"100.1",
"-100.1",
"100.13",
"-100.13",
"1,000",
"-1,000",
"10,123",
"-10,123",
"10,311",
"-10,311",
"100,000.13",
"-100,000.13",
"1,000,000",
"-1,000,000",
"1,234,567.1234567",
Expand Down

0 comments on commit fc41af6

Please sign in to comment.