|
15 | 15 | from django.utils import translation
|
16 | 16 | from django.utils.formats import (get_format, date_format, time_format,
|
17 | 17 | localize, localize_input, iter_format_modules, get_format_modules,
|
18 |
| - number_format) |
| 18 | + number_format, sanitize_separators) |
19 | 19 | from django.utils.importlib import import_module
|
20 | 20 | from django.utils.numberformat import format as nformat
|
21 | 21 | from django.utils._os import upath
|
@@ -669,6 +669,24 @@ def test_localized_input(self):
|
669 | 669 | # Checking for the localized "products_delivered" field
|
670 | 670 | self.assertInHTML('<input type="text" name="products_delivered" value="12.000" id="id_products_delivered" />', form6.as_ul())
|
671 | 671 |
|
| 672 | + def test_sanitize_separators(self): |
| 673 | + """ |
| 674 | + Tests django.utils.formats.sanitize_separators. |
| 675 | + """ |
| 676 | + # Non-strings are untouched |
| 677 | + self.assertEqual(sanitize_separators(123), 123) |
| 678 | + |
| 679 | + with translation.override('ru', deactivate=True): |
| 680 | + # Russian locale has non-breaking space (\xa0) as thousand separator |
| 681 | + # Check that usual space is accepted too when sanitizing inputs |
| 682 | + with self.settings(USE_THOUSAND_SEPARATOR=True): |
| 683 | + self.assertEqual(sanitize_separators('1\xa0234\xa0567'), '1234567') |
| 684 | + self.assertEqual(sanitize_separators('77\xa0777,777'), '77777.777') |
| 685 | + self.assertEqual(sanitize_separators('12 345'), '12345') |
| 686 | + self.assertEqual(sanitize_separators('77 777,777'), '77777.777') |
| 687 | + with self.settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=False): |
| 688 | + self.assertEqual(sanitize_separators('12\xa0345'), '12\xa0345') |
| 689 | + |
672 | 690 | def test_iter_format_modules(self):
|
673 | 691 | """
|
674 | 692 | Tests the iter_format_modules function.
|
|
0 commit comments