Ticket #22171: 22171-2.diff

File 22171-2.diff, 1.8 KB (added by Claude Paroz, 11 years ago)

Alternate patch

  • django/utils/formats.py

    diff --git a/django/utils/formats.py b/django/utils/formats.py
    index fc68179..6617142 100644
    a b def sanitize_separators(value):  
    213213            parts.append(decimals)
    214214        if settings.USE_THOUSAND_SEPARATOR:
    215215            thousand_sep = get_format('THOUSAND_SEPARATOR')
    216             for replacement in set([
    217                     thousand_sep, unicodedata.normalize('NFKD', thousand_sep)]):
    218                 value = value.replace(replacement, '')
     216            if thousand_sep == '.' and value.count('.') == 1 and len(value.split('.')[-1]) != 3:
     217                # Special case where we suspect a dot meant decimal separator (see #22171)
     218                pass
     219            else:
     220                for replacement in set([
     221                        thousand_sep, unicodedata.normalize('NFKD', thousand_sep)]):
     222                    value = value.replace(replacement, '')
    219223        parts.append(value)
    220224        value = '.'.join(reversed(parts))
    221225    return value
  • tests/i18n/tests.py

    diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
    index 1d34f90..3770aa4 100644
    a b class FormattingTests(TestCase):  
    720720            with self.settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=False):
    721721                self.assertEqual(sanitize_separators('12\xa0345'), '12\xa0345')
    722722
     723        with patch_formats(get_language(), THOUSAND_SEPARATOR='.', DECIMAL_SEPARATOR=','):
     724            with self.settings(USE_THOUSAND_SEPARATOR=True):
     725                self.assertEqual(sanitize_separators('10.234'), '10234')
     726                # Suspicion that user entered dot as decimal separator (#22171)
     727                self.assertEqual(sanitize_separators('10.10'), '10.10')
     728
    723729    def test_iter_format_modules(self):
    724730        """
    725731        Tests the iter_format_modules function.
Back to Top