mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Fixed #22171 -- Improved sanitize_separators cleverness
Thanks Klaas van Schelven for the report and Tim Graham for the review.
This commit is contained in:
parent
a3d7f58151
commit
132d0e516e
@ -221,9 +221,13 @@ def sanitize_separators(value):
|
|||||||
parts.append(decimals)
|
parts.append(decimals)
|
||||||
if settings.USE_THOUSAND_SEPARATOR:
|
if settings.USE_THOUSAND_SEPARATOR:
|
||||||
thousand_sep = get_format('THOUSAND_SEPARATOR')
|
thousand_sep = get_format('THOUSAND_SEPARATOR')
|
||||||
for replacement in set([
|
if thousand_sep == '.' and value.count('.') == 1 and len(value.split('.')[-1]) != 3:
|
||||||
thousand_sep, unicodedata.normalize('NFKD', thousand_sep)]):
|
# Special case where we suspect a dot meant decimal separator (see #22171)
|
||||||
value = value.replace(replacement, '')
|
pass
|
||||||
|
else:
|
||||||
|
for replacement in set([
|
||||||
|
thousand_sep, unicodedata.normalize('NFKD', thousand_sep)]):
|
||||||
|
value = value.replace(replacement, '')
|
||||||
parts.append(value)
|
parts.append(value)
|
||||||
value = '.'.join(reversed(parts))
|
value = '.'.join(reversed(parts))
|
||||||
return value
|
return value
|
||||||
|
@ -734,6 +734,12 @@ class FormattingTests(TestCase):
|
|||||||
with self.settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=False):
|
with self.settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=False):
|
||||||
self.assertEqual(sanitize_separators('12\xa0345'), '12\xa0345')
|
self.assertEqual(sanitize_separators('12\xa0345'), '12\xa0345')
|
||||||
|
|
||||||
|
with patch_formats(get_language(), THOUSAND_SEPARATOR='.', DECIMAL_SEPARATOR=','):
|
||||||
|
with self.settings(USE_THOUSAND_SEPARATOR=True):
|
||||||
|
self.assertEqual(sanitize_separators('10.234'), '10234')
|
||||||
|
# Suspicion that user entered dot as decimal separator (#22171)
|
||||||
|
self.assertEqual(sanitize_separators('10.10'), '10.10')
|
||||||
|
|
||||||
def test_iter_format_modules(self):
|
def test_iter_format_modules(self):
|
||||||
"""
|
"""
|
||||||
Tests the iter_format_modules function.
|
Tests the iter_format_modules function.
|
||||||
|
Loading…
Reference in New Issue
Block a user