You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WebVTT: a cue with a bare '<' or misnested end tags is dropped #1078
WebVTTCueBlock.parse raises on two kinds of cue text that occur in real subtitle files. WebVTTFile.parse then skips the cue, so converting a .vtt with docling silently loses it while the conversion still reports SUCCESS.
A bare < in the text, e.g. If x < 5 then stop, <3 you, a <- b. The leftover < ends up in a WebVTTCueTextSpan, whose validator rejects it.
Misnested end tags, e.g. <b><i>bold italic</b></i>. This raises ValueError: Incorrect end tag.
Steps to reproduce
fromdocling_core.types.doc.webvttimportWebVTTCueBlockforpayloadin ["If x < 5 then stop", "<3 you", "a <- b", "<b><i>bold italic</b></i>", "<i>one</b> two</i>"]:
try:
WebVTTCueBlock.parse(f"00:01.000 --> 00:02.000\n{payload}")
print("ok ", payload)
exceptExceptionase:
print("DROPPED", payload, "->", str(e).splitlines()[0][:80])
All five are dropped on main (2.108.0). End to end, a 3-cue file whose middle cue is If x < 5 then stop converts to only ['First cue', 'Third cue'].
Expected
Misnested end tags: the WebVTT cue text parsing rules (§6.4, end tag handling) say that an end tag which does not close the current node is ignored ("Otherwise, ignore the token"). So <b><i>x</b></i> should give <b><i>x</i></b>, and <i>one</b> two</i> should give <i>one two</i>. fix(webvtt): keep the text of unclosed spans and ignore stray end tags #875 quoted this rule but kept the error for scope reasons.
Bare <: strictly, the spec tokenizer treats < as the start of a tag, so browsers swallow the text up to the next > or the end of the cue. Following the precedent of fix(webvtt): ignore tags that are not cue spans instead of dropping the cue #896 (keep text rather than lose it), I'd propose keeping the < as literal text, so the cue text stays If x < 5 then stop. Happy to switch to the strict behaviour if you prefer.
All five payloads are dropped on the current main:
Payload
Failure on main
If x < 5 then stop
ValidationError: Cue text contains invalid characters
<3 you
ValidationError: Cue text contains invalid characters
a <- b
ValidationError: Cue text contains invalid characters
<b><i>bold italic</b></i>
ValueError: Incorrect end tag: i
<i>one</b> two</i>
ValueError: Incorrect end tag: i
The end-to-end claim is correct as well: a three-cue file whose middle cue is If x < 5 then stop parses to ['First cue', 'Last cue'] on main, and WebVTTFile.parse only emits a RuntimeWarning ("Failed to parse cue block"). Silent data loss in a converter is a legitimate bug, and both patterns occur in files produced by hand or by sloppy captioning tools.
Worth noting for the record: a cue text span may not contain < or & per §4.2.2 ("A WebVTT cue text span consists of one or more characters other than U+000A LINE FEED (LF) characters, U+000D CARRIAGE RETURN (CR) characters, U+0026 AMPERSAND characters (&), and U+003C LESS-THAN SIGN characters (<)"). So the inputs are non-conforming files in the first place.
Regarding the 2 distinct cases that you identified:
Misnested end tags
Indeed, §6.4 says an end tag moves current to its parent only when it matches the current node, and otherwise to ignore the token:
If any of the following conditions is true, then let current be the parent node of current. The tag name of the end tag token token is "c" and current is a WebVTT Class Object. [...] The tag name [...] is "ruby" and current is a WebVTT Ruby Object. [...]
Otherwise, if the tag name of the end tag token token is "lang" and current is a WebVTT Language Object, then let current be the parent node of current, and pop the top value from the language stack.
Otherwise, if the tag name of the end tag token token is "ruby" and current is a WebVTT Ruby Text Object, then let current be the parent node of the parent node of current.
Otherwise, ignore the token.
Therefore, I would favor handling this case leniently.
Bare <
The spec tokenizer does not keep a bare <. Handling this case as you suggest would be a deliberate deviation.
Two further facts from the spec and the Web Platform Tests (WPT) frame what this deviation costs:
First, a cue text span may not contain < at all (§4.2.2), so only no conforming files are affected
Second, a user agent is specified to lose the text: the WPT cue-text-parsing/tests/tags.html suite pins input: '<' to an empty document fragment, and the tokenizer rules make If x < 5 then stop render as If x . So your suggestion would produce text that no player would show. The spec is explicit that these two things are separate concerns: "§6 Parsing defines how user agents are to interpret a file labelled as text/vtt, for both valid and invalid WebVTT files. The parsing rules are more tolerant to author errors than the syntax allows [...] This is clearly a mistake, so a conformance checker will flag it as an error, but it is still useful to render the cues to the user." A cue also consists of "A cue text — The raw text of the cue, and rules for its interpretation", and VTTCue.text keeps that raw string while getCueAsHTML() is what applies §6.4/§6.5, so a text extractor has a legitimate second view of the cue besides the rendered fragment. By the way, this deviation would not be quite the same as fix(webvtt): ignore tags that are not cue spans instead of dropping the cue #896 : that change removed unknown tags whose text the spec keeps, whereas here the text is kept where the spec drops it. Be aware of what the lenient choice implies:
(a) docling's output no longer matches what a user agent renders, so it will disagree with a browser, the validator or another tool on these cues;
(b) it is a repair rather than a transcription, because the export escapes < as <, so the re-emitted file is conforming and shows text the original file never rendered;
(c) the rule is broader than the four examples in the issue, since every < that does not start a complete cue tag becomes text, which also keeps invalid timestamp tags (<00:99.000>) and truncated tags (a <b);
(d) the module can no longer be checked against the WPT cue-text tests wholesale, so the deviation has to be pinned by tests and documented.
@aad1tyaaaaa can you point to real WebVTT files produced by widely adopted applications that include the case of the bare < ? This would help us understand how to shape a robust resolution of these cases.
For now, my suggestion would be to drop the bare < half of this issue and focus on the misnested end tags (e.g., the last two of the five payloads in the examples above).
Thanks for the careful spec and WPT analysis. I don't have real files from widely used tools with a bare <; my examples were hand-written, so I agree it's better not to deviate from the spec there. I've narrowed #1079 to the misnested end tags only, which are now ignored as §6.4 says, and dropped the bare < handling and its test.
Thanks for narrowing #1079 to the misnested end tags, and for confirming the bare < case. That keeps the change aligned with the spec.
One general note: with the number of open issues and PRs we have, we're focusing on bugs and features that come from real use cases. Future issues are very welcome. A real sample file, or a description of where the input comes from, helps us prioritize. We value all contributions, including this one. Thanks!
Activity
ceberam commentedon Nov 26, 2026
Thanks @aad1tyaaaaa for opening this issue.
All five payloads are dropped on the current
main:mainIf x < 5 then stopValidationError: Cue text contains invalid characters<3 youValidationError: Cue text contains invalid charactersa <- bValidationError: Cue text contains invalid characters<b><i>bold italic</b></i>ValueError: Incorrect end tag: i<i>one</b> two</i>ValueError: Incorrect end tag: iThe end-to-end claim is correct as well: a three-cue file whose middle cue is
If x < 5 then stopparses to['First cue', 'Last cue']onmain, andWebVTTFile.parseonly emits aRuntimeWarning("Failed to parse cue block"). Silent data loss in a converter is a legitimate bug, and both patterns occur in files produced by hand or by sloppy captioning tools.Worth noting for the record: a cue text span may not contain
<or&per §4.2.2 ("A WebVTT cue text span consists of one or more characters other than U+000A LINE FEED (LF) characters, U+000D CARRIAGE RETURN (CR) characters, U+0026 AMPERSAND characters (&), and U+003C LESS-THAN SIGN characters (<)"). So the inputs are non-conforming files in the first place.Regarding the 2 distinct cases that you identified:
Misnested end tags
Indeed, §6.4 says an end tag moves
currentto its parent only when it matches the current node, and otherwise to ignore the token:Therefore, I would favor handling this case leniently.
Bare
<The spec tokenizer does not keep a bare
<. Handling this case as you suggest would be a deliberate deviation.Two further facts from the spec and the Web Platform Tests (WPT) frame what this deviation costs:
<at all (§4.2.2), so only no conforming files are affectedcue-text-parsing/tests/tags.htmlsuite pinsinput: '<'to an empty document fragment, and the tokenizer rules makeIf x < 5 then stoprender asIf x. So your suggestion would produce text that no player would show. The spec is explicit that these two things are separate concerns: "§6 Parsing defines how user agents are to interpret a file labelled as text/vtt, for both valid and invalid WebVTT files. The parsing rules are more tolerant to author errors than the syntax allows [...] This is clearly a mistake, so a conformance checker will flag it as an error, but it is still useful to render the cues to the user." A cue also consists of "A cue text — The raw text of the cue, and rules for its interpretation", andVTTCue.textkeeps that raw string whilegetCueAsHTML()is what applies §6.4/§6.5, so a text extractor has a legitimate second view of the cue besides the rendered fragment. By the way, this deviation would not be quite the same as fix(webvtt): ignore tags that are not cue spans instead of dropping the cue #896 : that change removed unknown tags whose text the spec keeps, whereas here the text is kept where the spec drops it. Be aware of what the lenient choice implies:<as<, so the re-emitted file is conforming and shows text the original file never rendered;<that does not start a complete cue tag becomes text, which also keeps invalid timestamp tags (<00:99.000>) and truncated tags (a <b);@aad1tyaaaaa can you point to real WebVTT files produced by widely adopted applications that include the case of the bare
<? This would help us understand how to shape a robust resolution of these cases.For now, my suggestion would be to drop the bare
<half of this issue and focus on the misnested end tags (e.g., the last two of the five payloads in the examples above).aad1tyaaaaa commentedon Nov 27, 2026
Thanks for the careful spec and WPT analysis. I don't have real files from widely used tools with a bare
<; my examples were hand-written, so I agree it's better not to deviate from the spec there. I've narrowed #1079 to the misnested end tags only, which are now ignored as §6.4 says, and dropped the bare<handling and its test.ceberam commentedon Nov 27, 2026
Thanks for narrowing #1079 to the misnested end tags, and for confirming the bare
<case. That keeps the change aligned with the spec.One general note: with the number of open issues and PRs we have, we're focusing on bugs and features that come from real use cases. Future issues are very welcome. A real sample file, or a description of where the input comes from, helps us prioritize. We value all contributions, including this one. Thanks!