From 9b864d03380fc2df9f59c6890b2a012b3a4b9d6e Mon Sep 17 00:00:00 2001 From: Mohammad Khan Date: Mon, 14 Nov 2022 13:37:37 -0500 Subject: [PATCH 1/3] modify one or two digit regex Co-Authored by: Lukas Lemke <90070416+13MK3@users.noreply.github.com> --- arrow/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow/parser.py b/arrow/parser.py index ee31a5bc..9ccf88df 100644 --- a/arrow/parser.py +++ b/arrow/parser.py @@ -107,7 +107,7 @@ class DateTimeParser: ) _ESCAPE_RE: ClassVar[Pattern[str]] = re.compile(r"\[[^\[\]]*\]") - _ONE_OR_TWO_DIGIT_RE: ClassVar[Pattern[str]] = re.compile(r"\d{1,2}") + _ONE_OR_TWO_DIGIT_RE: ClassVar[Pattern[str]] = re.compile(r"[1-9]\d|\d") _ONE_OR_TWO_OR_THREE_DIGIT_RE: ClassVar[Pattern[str]] = re.compile(r"\d{1,3}") _ONE_OR_MORE_DIGIT_RE: ClassVar[Pattern[str]] = re.compile(r"\d+") _TWO_DIGIT_RE: ClassVar[Pattern[str]] = re.compile(r"\d{2}") From d3ebdd2ec09d059829adf18e1abc808a932bbf9f Mon Sep 17 00:00:00 2001 From: Mohammad Khan Date: Mon, 14 Nov 2022 13:39:18 -0500 Subject: [PATCH 2/3] modify existing test case Co-Authored by: Lukas Lemke <90070416+13MK3@users.noreply.github.com> --- tests/test_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_parser.py b/tests/test_parser.py index bdcc1026..07084c12 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -147,7 +147,7 @@ def test_YY_and_YYYY_format_list(self): assert self.parser.parse( "15/01/2019T04:05:06.789120Z", - ["D/M/YYThh:mm:ss.SZ", "D/M/YYYYThh:mm:ss.SZ"], + ["D/MM/YYThh:mm:ss.SZ", "D/MM/YYYYThh:mm:ss.SZ"], ) == datetime(2019, 1, 15, 4, 5, 6, 789120, tzinfo=tz.tzutc()) # regression test for issue #447 From 6bd3d7a7fc2dcfd84a1a5c6c7e83f80576279385 Mon Sep 17 00:00:00 2001 From: Mohammad Khan Date: Mon, 14 Nov 2022 14:10:52 -0500 Subject: [PATCH 3/3] add test case Co-Authored by: Lukas Lemke <90070416+13MK3@users.noreply.github.com> --- tests/test_parser.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_parser.py b/tests/test_parser.py index 07084c12..ee121af3 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -790,6 +790,23 @@ def test_parse_normalize_whitespace(self): with pytest.raises(ParserError): self.parser.parse(" \n Jun 1\t 2005\n ", "MMM D YYYY") + def test_parse_leading_zero(self): + # Regression tests for issue #1084 + with pytest.raises(ParserError): + self.parser.parse("01", "M") + + with pytest.raises(ParserError): + self.parser.parse("01", "D") + + with pytest.raises(ParserError): + self.parser.parse("01", "H") + + with pytest.raises(ParserError): + self.parser.parse("01", "h") + + with pytest.raises(ParserError): + self.parser.parse("01", "s") + @pytest.mark.usefixtures("dt_parser_regex") class TestDateTimeParserRegex: