Skip to content

Commit 203b6ee

Browse files
committed
fix parsing invalid interval string
1 parent a21fc8d commit 203b6ee

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/pendulum/parsing/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ def _parse_iso8601_interval(text: str) -> _Interval:
212212
raise ParserError("Invalid interval")
213213

214214
first, last = text.split("/")
215+
216+
if not first or not last:
217+
raise ParserError("Invalid interval.")
218+
215219
start = end = duration = None
216220

217221
if first[0] == "P":

tests/parsing/test_parsing_duration.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@ def test_parse_duration_invalid():
293293
parse("P1Dasdfasdf")
294294

295295

296+
def test_parse_interval_invalid():
297+
with pytest.raises(ParserError):
298+
parse("/no_start")
299+
300+
with pytest.raises(ParserError):
301+
parse("no_end/")
302+
303+
296304
def test_parse_duration_fraction_only_allowed_on_last_component():
297305
with pytest.raises(ParserError):
298306
parse("P2Y3M4DT5.5H6M7S")

0 commit comments

Comments
 (0)