diff --git a/src/main/python/ttconv/srt/reader.py b/src/main/python/ttconv/srt/reader.py index 5b1b89eb..747cd25f 100644 --- a/src/main/python/ttconv/srt/reader.py +++ b/src/main/python/ttconv/srt/reader.py @@ -285,6 +285,7 @@ def to_model(data_file: typing.IO, _config: SRTReaderConfiguration = None, progr int(m.group('end_ms')) / 1000 ) + subtitle_text = None state = _State.TEXT continue @@ -292,6 +293,12 @@ def to_model(data_file: typing.IO, _config: SRTReaderConfiguration = None, progr 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 @@ -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: diff --git a/src/test/python/test_srt_reader.py b/src/test/python/test_srt_reader.py index e1c3f9df..0f57b354 100644 --- a/src/test/python/test_srt_reader.py +++ b/src/test/python/test_srt_reader.py @@ -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