diff options
| author | mendespedro <windowsxpedro@gmail.com> | 2021-12-15 13:56:04 -0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-12-20 06:46:34 +0100 |
| commit | 4fd3044ca0135da903a70dfb66992293f529ecf1 (patch) | |
| tree | 5884d724f07c6d3c39d9477cec8093796a239f1c | |
| parent | b0d16d0129b7cc5978a8d55d2331a34cb369e6c7 (diff) | |
Fixed #33368 -- Fixed parse_duration() crash on invalid separators for decimal fractions.
| -rw-r--r-- | django/utils/dateparse.py | 8 | ||||
| -rw-r--r-- | tests/forms_tests/field_tests/test_durationfield.py | 2 | ||||
| -rw-r--r-- | tests/utils_tests/test_dateparse.py | 5 |
3 files changed, 11 insertions, 4 deletions
diff --git a/django/utils/dateparse.py b/django/utils/dateparse.py index 238c727cb1..e2a806c8e8 100644 --- a/django/utils/dateparse.py +++ b/django/utils/dateparse.py @@ -42,11 +42,11 @@ standard_duration_re = _lazy_re_compile( iso8601_duration_re = _lazy_re_compile( r'^(?P<sign>[-+]?)' r'P' - r'(?:(?P<days>\d+(.\d+)?)D)?' + r'(?:(?P<days>\d+([\.,]\d+)?)D)?' r'(?:T' - r'(?:(?P<hours>\d+(.\d+)?)H)?' - r'(?:(?P<minutes>\d+(.\d+)?)M)?' - r'(?:(?P<seconds>\d+(.\d+)?)S)?' + r'(?:(?P<hours>\d+([\.,]\d+)?)H)?' + r'(?:(?P<minutes>\d+([\.,]\d+)?)M)?' + r'(?:(?P<seconds>\d+([\.,]\d+)?)S)?' r')?' r'$' ) diff --git a/tests/forms_tests/field_tests/test_durationfield.py b/tests/forms_tests/field_tests/test_durationfield.py index f5125aa571..dae139446d 100644 --- a/tests/forms_tests/field_tests/test_durationfield.py +++ b/tests/forms_tests/field_tests/test_durationfield.py @@ -30,6 +30,8 @@ class DurationFieldTest(FormFieldAssertionsMixin, SimpleTestCase): msg = 'Enter a valid duration.' with self.assertRaisesMessage(ValidationError, msg): f.clean('not_a_time') + with self.assertRaisesMessage(ValidationError, msg): + DurationField().clean('P3(3D') def test_durationfield_clean_not_required(self): f = DurationField(required=False) diff --git a/tests/utils_tests/test_dateparse.py b/tests/utils_tests/test_dateparse.py index 0880de2034..f2f66f351d 100644 --- a/tests/utils_tests/test_dateparse.py +++ b/tests/utils_tests/test_dateparse.py @@ -161,6 +161,11 @@ class DurationParseTests(unittest.TestCase): ('-PT0.000005S', timedelta(microseconds=-5)), ('-PT0,000005S', timedelta(microseconds=-5)), ('-P4DT1H', timedelta(days=-4, hours=-1)), + # Invalid separators for decimal fractions. + ('P3(3D', None), + ('PT3)3H', None), + ('PT3|3M', None), + ('PT3/3S', None), ) for source, expected in test_values: with self.subTest(source=source): |
