Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force exact match on .get() #1142

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion arrow/parser.py
Expand Up @@ -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}")
Expand Down
19 changes: 18 additions & 1 deletion tests/test_parser.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down