Skip to content
Closed
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
1 change: 1 addition & 0 deletions src/main/python/ttconv/srt/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def to_model(data_file: typing.IO, _config: SRTReaderConfiguration = None, progr
return None

current_p = model.P(doc)
subtitle_text = ""

current_p.set_begin(
int(m.group('begin_h')) * 3600 +
Expand Down
2 changes: 2 additions & 0 deletions src/main/python/ttconv/vtt/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ class _State(Enum):
for line_index, line in enumerate(_none_terminated(lines)):

if state is _State.START:
if line is None:
break
if not line.startswith("WEBVTT"):
LOGGER.warning("The first line of the file does not start with WEBVTT")
state = _State.LOOKING
Expand Down
13 changes: 13 additions & 0 deletions src/test/python/test_srt_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,19 @@ def test_alignment_multiple_tags_uses_first(self):
self.assertNotIn("{\\an", text_content)
self.assertIn("Multiple tags here", text_content)

def test_empty_cue_text(self):
# A cue whose text body is empty (a time line immediately followed by a
# blank line) used to raise UnboundLocalError.
f = io.StringIO(
"1\n"
"00:00:01,000 --> 00:00:04,000\n"
"\n"
"2\n"
"00:00:05,000 --> 00:00:08,000\n"
"Second\n"
)
self.assertIsNotNone(to_model(f))


if __name__ == '__main__':
unittest.main()
5 changes: 5 additions & 0 deletions src/test/python/test_vtt_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,5 +438,10 @@ def test_default_positioning(self):
self.assertEqual(o.x.value, 100*1/40)
self.assertEqual(e.width.value, 100 - 2*100*1/40)

def test_empty_input(self):
# An empty document used to raise AttributeError on the None sentinel.
self.assertIsNotNone(to_model(io.StringIO("")))
self.assertIsNotNone(to_model(io.StringIO(" \n")))

if __name__ == '__main__':
unittest.main()