Skip to content

Fix parse invalid interval string #860

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions src/pendulum/parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ def _parse_iso8601_interval(text: str) -> _Interval:
raise ParserError("Invalid interval")

first, last = text.split("/")

if not first or not last:
raise ParserError("Invalid interval.")

start = end = duration = None

if first[0] == "P":
Expand Down
8 changes: 8 additions & 0 deletions tests/parsing/test_parsing_duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ def test_parse_duration_invalid():
parse("P1Dasdfasdf")


def test_parse_interval_invalid():
with pytest.raises(ParserError):
parse("/no_start")

with pytest.raises(ParserError):
parse("no_end/")


def test_parse_duration_fraction_only_allowed_on_last_component():
with pytest.raises(ParserError):
parse("P2Y3M4DT5.5H6M7S")
Loading