Skip to content

Commit

Permalink
fix parsing invalid interval string
Browse files Browse the repository at this point in the history
  • Loading branch information
rchindris committed Nov 15, 2024
1 parent a21fc8d commit 203b6ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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")

0 comments on commit 203b6ee

Please sign in to comment.