Fixed #33368 -- Fixed parse_duration() crash on invalid separators for decimal fractions.
This commit is contained in:
parent
b0d16d0129
commit
4fd3044ca0
|
@ -42,11 +42,11 @@ standard_duration_re = _lazy_re_compile(
|
||||||
iso8601_duration_re = _lazy_re_compile(
|
iso8601_duration_re = _lazy_re_compile(
|
||||||
r'^(?P<sign>[-+]?)'
|
r'^(?P<sign>[-+]?)'
|
||||||
r'P'
|
r'P'
|
||||||
r'(?:(?P<days>\d+(.\d+)?)D)?'
|
r'(?:(?P<days>\d+([\.,]\d+)?)D)?'
|
||||||
r'(?:T'
|
r'(?:T'
|
||||||
r'(?:(?P<hours>\d+(.\d+)?)H)?'
|
r'(?:(?P<hours>\d+([\.,]\d+)?)H)?'
|
||||||
r'(?:(?P<minutes>\d+(.\d+)?)M)?'
|
r'(?:(?P<minutes>\d+([\.,]\d+)?)M)?'
|
||||||
r'(?:(?P<seconds>\d+(.\d+)?)S)?'
|
r'(?:(?P<seconds>\d+([\.,]\d+)?)S)?'
|
||||||
r')?'
|
r')?'
|
||||||
r'$'
|
r'$'
|
||||||
)
|
)
|
||||||
|
|
|
@ -30,6 +30,8 @@ class DurationFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
|
||||||
msg = 'Enter a valid duration.'
|
msg = 'Enter a valid duration.'
|
||||||
with self.assertRaisesMessage(ValidationError, msg):
|
with self.assertRaisesMessage(ValidationError, msg):
|
||||||
f.clean('not_a_time')
|
f.clean('not_a_time')
|
||||||
|
with self.assertRaisesMessage(ValidationError, msg):
|
||||||
|
DurationField().clean('P3(3D')
|
||||||
|
|
||||||
def test_durationfield_clean_not_required(self):
|
def test_durationfield_clean_not_required(self):
|
||||||
f = DurationField(required=False)
|
f = DurationField(required=False)
|
||||||
|
|
|
@ -161,6 +161,11 @@ class DurationParseTests(unittest.TestCase):
|
||||||
('-PT0.000005S', timedelta(microseconds=-5)),
|
('-PT0.000005S', timedelta(microseconds=-5)),
|
||||||
('-PT0,000005S', timedelta(microseconds=-5)),
|
('-PT0,000005S', timedelta(microseconds=-5)),
|
||||||
('-P4DT1H', timedelta(days=-4, hours=-1)),
|
('-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:
|
for source, expected in test_values:
|
||||||
with self.subTest(source=source):
|
with self.subTest(source=source):
|
||||||
|
|
Loading…
Reference in New Issue