Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arrow/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class DateTimeParser:
_TZ_NAME_RE: ClassVar[Pattern[str]] = re.compile(r"\w[\w+\-/]+")
# NOTE: timestamps cannot be parsed from natural language strings (by removing the ^...$) because it will
# break cases like "15 Jul 2000" and a format list (see issue #447)
_TIMESTAMP_RE: ClassVar[Pattern[str]] = re.compile(r"^\-?\d+\.?\d+$")
_TIMESTAMP_RE: ClassVar[Pattern[str]] = re.compile(r"^\-?(?:\d+\.\d+|\d{2,})$")
_TIMESTAMP_EXPANDED_RE: ClassVar[Pattern[str]] = re.compile(r"^\-?\d+$")
_TIME_RE: ClassVar[Pattern[str]] = re.compile(
r"^(\d{2})(?:\:?(\d{2}))?(?:\:?(\d{2}))?(?:([\.\,])(\d+))?$"
Expand Down
9 changes: 9 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ def test_parse_timestamp(self):
with pytest.raises(ParserError):
self.parser.parse(".1565982019", "X")

def test_parse_timestamp_long_invalid_input(self):
# a long digit run followed by a non-digit character used to trigger
# quadratic backtracking in the timestamp regex (_TIMESTAMP_RE)
malformed = "9" * 50000 + "!"
start = time.perf_counter()
with pytest.raises(ParserError):
self.parser.parse(malformed, "X")
assert time.perf_counter() - start < 1.0

# NOTE: negative timestamps cannot be handled by datetime on Windows
# Must use timedelta to handle them: https://stackoverflow.com/questions/36179914
@pytest.mark.skipif(
Expand Down