diff options
| author | Jimmy Angelakos <vyruss@hellug.gr> | 2022-09-10 14:04:45 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-09-12 12:54:12 +0200 |
| commit | e911e0996f1096cc23ef03b1ca70da7499dd8f2f (patch) | |
| tree | cb3d4d4f5652b3bc686da1b9eb85a8b197dd1a9e | |
| parent | ec13e801b820614ff374cb0046092caab8d67249 (diff) | |
Fixed #34000 -- Fixed numberformat.format() crash on empty strings.
| -rw-r--r-- | django/utils/numberformat.py | 2 | ||||
| -rw-r--r-- | tests/utils_tests/test_numberformat.py | 3 |
2 files changed, 5 insertions, 0 deletions
diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py index 488d6a77cd..35bbdd39e1 100644 --- a/django/utils/numberformat.py +++ b/django/utils/numberformat.py @@ -25,6 +25,8 @@ def format( module in locale.localeconv() LC_NUMERIC grouping (e.g. (3, 2, 0)). * thousand_sep: Thousand separator symbol (for example ",") """ + if number == "": + return mark_safe(number) use_grouping = ( use_l10n or (use_l10n is None and settings.USE_L10N) ) and settings.USE_THOUSAND_SEPARATOR diff --git a/tests/utils_tests/test_numberformat.py b/tests/utils_tests/test_numberformat.py index cec3e4c385..59fa421682 100644 --- a/tests/utils_tests/test_numberformat.py +++ b/tests/utils_tests/test_numberformat.py @@ -172,3 +172,6 @@ class TestNumberFormat(SimpleTestCase): price = EuroDecimal("1.23") self.assertEqual(nformat(price, ","), "€ 1,23") + + def test_empty(self): + self.assertEqual(nformat("", "."), "") |
