Skip to content

Commit

Permalink
Fix parsing invalid intervals
Browse files Browse the repository at this point in the history
Parsing string with slash at the start or the end raised IndexError
instead of ParseError.
  • Loading branch information
wiget committed Sep 11, 2024
1 parent 3e3fec6 commit 0992d8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pendulum/parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ def _parse_iso8601_interval(text: str) -> _Interval:
first, last = text.split("/")
start = end = duration = None

if first[0] == "P":
if first[0:1] == "P":
# duration/end
duration = parse_iso8601(first)
end = parse_iso8601(last)
elif last[0] == "P":
elif last[0:1] == "P":
# start/duration
start = parse_iso8601(first)
duration = parse_iso8601(last)
Expand Down
10 changes: 10 additions & 0 deletions tests/parsing/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,16 @@ def test_invalid():
with pytest.raises(ParserError):
parse(text)

text = "/2012"

with pytest.raises(ParserError):
parse(text)

text = "2012/"

with pytest.raises(ParserError):
parse(text)


def test_exif_edge_case():
text = "2016:12:26 15:45:28"
Expand Down

0 comments on commit 0992d8c

Please sign in to comment.