Skip to content
Merged
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
10 changes: 10 additions & 0 deletions tests/test_vobject_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ def test_bad_stream():
vobject.base.readOne(bad_stream)


def test_empty_stream():
"""
An empty or whitespace-only stream has no components and used to raise a
bare StopIteration; it should raise ParseError.
"""
for stream in ("", " ", "\n\n\t"):
with pytest.raises(vobject.base.ParseError):
vobject.base.readOne(stream)


def test_bad_line():
"""
Test bad line in ics file
Expand Down
7 changes: 6 additions & 1 deletion vobject/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,12 @@ def readOne(stream, validate=False, transform=True, ignoreUnreadable=False, allo
"""
Return the first component from stream.
"""
return next(readComponents(stream, validate, transform, ignoreUnreadable, allowQP))
try:
return next(readComponents(stream, validate, transform, ignoreUnreadable, allowQP))
except StopIteration:
# An empty (or whitespace-only) stream yields no components; report it
# as a parse error instead of letting a bare StopIteration escape.
raise ParseError("No components in stream")


# --------------------------- version registry ---------------------------------
Expand Down