summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2024-02-08 10:58:54 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2024-02-08 11:03:21 +0100
commitfc41af69a2e49a717ef069a37e1d68b80a6a5d56 (patch)
tree4fa46cbd9da61200f2bfcd4691c3f3c096d6bd78
parentb9170b4a9e7f0dde5d29ef69354c94efa6d6edfb (diff)
[3.2.x] Fixed #35172 -- Fixed intcomma for string floats.
Thanks Warwick Brown for the report. Regression in 55519d6cf8998fe4c8f5c8abffc2b10a7c3d14e9. Backport of 2f14c2cedc9c92373471c1f98a80c81ba299584a from main.
-rw-r--r--django/contrib/humanize/templatetags/humanize.py2
-rw-r--r--docs/releases/3.2.25.txt13
-rw-r--r--docs/releases/index.txt1
-rw-r--r--tests/humanize_tests/tests.py12
4 files changed, 28 insertions, 0 deletions
diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py
index 238aaf2253..dc88e4a694 100644
--- a/django/contrib/humanize/templatetags/humanize.py
+++ b/django/contrib/humanize/templatetags/humanize.py
@@ -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
diff --git a/docs/releases/3.2.25.txt b/docs/releases/3.2.25.txt
new file mode 100644
index 0000000000..c84483f783
--- /dev/null
+++ b/docs/releases/3.2.25.txt
@@ -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`).
diff --git a/docs/releases/index.txt b/docs/releases/index.txt
index 38fc2a47b6..08db69ed58 100644
--- a/docs/releases/index.txt
+++ b/docs/releases/index.txt
@@ -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
diff --git a/tests/humanize_tests/tests.py b/tests/humanize_tests/tests.py
index 3c227873cf..d6d7ea02ad 100644
--- a/tests/humanize_tests/tests.py
+++ b/tests/humanize_tests/tests.py
@@ -80,12 +80,18 @@ class HumanizeTests(SimpleTestCase):
-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",
@@ -114,12 +120,18 @@ class HumanizeTests(SimpleTestCase):
"-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",