Skip to content

Commit 6205754

Browse files
authored
Fix parsing invalid intervals (#843)
* Fix parsing invalid intervals Parsing string with slash at the start or the end raised IndexError instead of ParseError. * Apply suggestion from review
1 parent 51fb4c3 commit 6205754

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/pendulum/parsing/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ def _parse_iso8601_interval(text: str) -> _Interval:
214214
first, last = text.split("/")
215215
start = end = duration = None
216216

217-
if first[0] == "P":
217+
if first[:1] == "P":
218218
# duration/end
219219
duration = parse_iso8601(first)
220220
end = parse_iso8601(last)
221-
elif last[0] == "P":
221+
elif last[:1] == "P":
222222
# start/duration
223223
start = parse_iso8601(first)
224224
duration = parse_iso8601(last)

tests/parsing/test_parsing.py

+10
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,16 @@ def test_invalid():
660660
with pytest.raises(ParserError):
661661
parse(text)
662662

663+
text = "/2012"
664+
665+
with pytest.raises(ParserError):
666+
parse(text)
667+
668+
text = "2012/"
669+
670+
with pytest.raises(ParserError):
671+
parse(text)
672+
663673

664674
def test_exif_edge_case():
665675
text = "2016:12:26 15:45:28"

0 commit comments

Comments
 (0)