From cf6774a53b40243d35183b4300a9385b68fd8c75 Mon Sep 17 00:00:00 2001 From: abhiabhi94 <13880786+abhiabhi94@users.noreply.github.com> Date: Wed, 7 Jul 2021 12:51:12 +0530 Subject: [PATCH] Fixed #32904 -- Made parse_time() more strict. Thanks Keryn Knight for the report. --- django/utils/dateparse.py | 2 +- tests/utils_tests/test_dateparse.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/django/utils/dateparse.py b/django/utils/dateparse.py index 60840933d5..238c727cb1 100644 --- a/django/utils/dateparse.py +++ b/django/utils/dateparse.py @@ -16,7 +16,7 @@ date_re = _lazy_re_compile( time_re = _lazy_re_compile( r'(?P\d{1,2}):(?P\d{1,2})' - r'(?::(?P\d{1,2})(?:[\.,](?P\d{1,6})\d{0,6})?)?' + r'(?::(?P\d{1,2})(?:[\.,](?P\d{1,6})\d{0,6})?)?$' ) datetime_re = _lazy_re_compile( diff --git a/tests/utils_tests/test_dateparse.py b/tests/utils_tests/test_dateparse.py index 9974b85f07..0880de2034 100644 --- a/tests/utils_tests/test_dateparse.py +++ b/tests/utils_tests/test_dateparse.py @@ -27,10 +27,12 @@ class DateParseTests(unittest.TestCase): self.assertEqual(parse_time('4:8:16'), time(4, 8, 16)) # Time zone offset is ignored. self.assertEqual(parse_time('00:05:23+04:00'), time(0, 5, 23)) - # These should be invalid, see #32904. - self.assertEqual(parse_time('00:05:'), time(0, 5)) - self.assertEqual(parse_time('4:18:101'), time(4, 18, 10)) # Invalid inputs + self.assertIsNone(parse_time('00:05:')) + self.assertIsNone(parse_time('00:05:23,')) + self.assertIsNone(parse_time('00:05:23+')) + self.assertIsNone(parse_time('00:05:23+25:00')) + self.assertIsNone(parse_time('4:18:101')) self.assertIsNone(parse_time('091500')) with self.assertRaises(ValueError): parse_time('09:15:90')