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
8 changes: 7 additions & 1 deletion src/main/python/ttconv/srt/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,20 @@ def to_model(data_file: typing.IO, _config: SRTReaderConfiguration = None, progr
int(m.group('end_ms')) / 1000
)

subtitle_text = None
state = _State.TEXT

continue

if state in (_State.TEXT, _State.TEXT_MORE):

if line is None or _EMPTY_RE.fullmatch(line):
state = _State.COUNTER

if subtitle_text is None:
LOGGER.warning("Ignoring cue due to a spurious blank line at line %s", line_index)
continue

subtitle_text = subtitle_text.strip('\r\n').replace(r"\n\r", "\n")

# Extract and handle alignment tags if enabled
Expand Down Expand Up @@ -328,7 +335,6 @@ def to_model(data_file: typing.IO, _config: SRTReaderConfiguration = None, progr
parser.feed(subtitle_text)
parser.close()

state = _State.COUNTER
continue

if state is _State.TEXT:
Expand Down
12 changes: 12 additions & 0 deletions src/test/python/test_srt_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ def test_single_line_text(self):
self.assertIsInstance(p_children[0], model.Span)
self.assertEqual(p_children[0].first_child().get_text(), "Hello")

def test_spurious_emtpy_line(self):
f = io.StringIO(r"""1
101:00:00,000 --> 101:00:01,000

2
101:00:00,000 --> 101:00:01,000
Bonjour
""")
doc = to_model(f)
self.assertIsNotNone(doc)
self.assertEqual(len(doc.get_body()), 1)

def test_multiline_text(self):
f = io.StringIO(r"""1
101:00:00,000 --> 101:00:01,000
Expand Down