Fixed #34000 -- Fixed numberformat.format() crash on empty strings.

This commit is contained in:
Jimmy Angelakos 2022-09-10 14:04:45 +01:00 committed by Mariusz Felisiak
parent ec13e801b8
commit e911e0996f
2 changed files with 5 additions and 0 deletions

View File

@ -25,6 +25,8 @@ def format(
module in locale.localeconv() LC_NUMERIC grouping (e.g. (3, 2, 0)). module in locale.localeconv() LC_NUMERIC grouping (e.g. (3, 2, 0)).
* thousand_sep: Thousand separator symbol (for example ",") * thousand_sep: Thousand separator symbol (for example ",")
""" """
if number == "":
return mark_safe(number)
use_grouping = ( use_grouping = (
use_l10n or (use_l10n is None and settings.USE_L10N) use_l10n or (use_l10n is None and settings.USE_L10N)
) and settings.USE_THOUSAND_SEPARATOR ) and settings.USE_THOUSAND_SEPARATOR

View File

@ -172,3 +172,6 @@ class TestNumberFormat(SimpleTestCase):
price = EuroDecimal("1.23") price = EuroDecimal("1.23")
self.assertEqual(nformat(price, ","), "€ 1,23") self.assertEqual(nformat(price, ","), "€ 1,23")
def test_empty(self):
self.assertEqual(nformat("", "."), "")