Skip to content

fix(webvtt): escape cue text and voice names when exporting to WebVTT - #972

Merged
ceberam merged 2 commits into
docling-project:mainfrom
Fahmid-Arman:fix/webvtt-export-escaping
Nov 13, 2026
Merged

ceberam merged 2 commits into
docling-project:mainfrom
Fahmid-Arman:fix/webvtt-export-escaping

Conversation

@Fahmid-Arman

Copy link
Copy Markdown
Contributor

Resolves #971

export_to_vtt() crashed with a ValidationError when a cue's text or voice name contained & or <, and wrote a literal &amp; unescaped, so it read back as &.

WebVTTTextSerializer built the cue text from the raw item.text, and _add_span used the raw voice name as the <v> annotation. serialize_doc then parses that text with WebVTTCueBlock.parse, which decodes escapes since #776. Both now go through the existing _escape helper from docling_core.types.doc.webvtt, with the right terminator for each:

  • < for cue text;
  • > for annotations.

These are the same rules the parsed data model uses when it writes cues back out.

Review evidence

Cue Before After
text Tom & Jerry ValidationError Tom &amp; Jerry
text a < b ValidationError a &lt; b
text AT&amp;T AT&amp;T (reads back as AT&T) AT&amp;amp;T
voice Tom & Jerry ValidationError <v Tom &amp; Jerry>Hello</v>

Text without & or < is written exactly as before (> stays literal in cue text), so the existing WebVTT ground-truth files don't change.

  • New test_export_to_vtt_escapes_text_and_voice in tests/test_webvtt.py exports each case above and parses the result back. It checks the cue line and that the text and voice read back unchanged. All four cases fail on main and pass with the change.
  • uv run pytest tests: 1366 passed, 12 skipped, 1 xfailed.
  • ruff format and ruff check are clean.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @Fahmid-Arman, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 2 merge protections satisfied — ready to merge.

Show 2 satisfied protections

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

🟢 Require two reviewer for test updates

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working media Images, audio, video, WebVTT, PDF shapes/widgets, MIME types, ImageRef serialization Output serializers: Markdown, HTML, LaTeX, JSON, plain-text, outline labels Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit e65a82a3c8. The analysis read the diff only. It did not run code from this pull request.

The PR changes only tests/test_webvtt.py. It turns test_webvtt_export_keeps_text_literal into a parametrized test with four cases for cue text and voice names. The serializer fix that the PR text describes is not in the diff, and the base branch already calls _escape in docling_core/transforms/serializer/webvtt.py.

CI safety: no concern found. A maintainer must still approve CI.

Possible duplicates

PR State Signal Assessment
#926 merged also references issue #971 duplicate: Merged PR #926 already added the export escaping and test_webvtt_export_keeps_text_literal, which this PR only rewrites. It also references #971.
1 related pull request(s) in the same code
PR State Signal Assessment
#776 merged referenced as #776 related: Merged PR #776 added the decoding of escapes in cue text and annotations when the parser reads them. This PR tests the export path and does not repeat that change.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the full diff at efaf5562ea. It read the code and did not run it.

No blocking finding. I traced item.text and the voice name through post_process, WebVTTCueBlock.parse, and WebVTTCueTextSpan / WebVTTCueSpanStartTagAnnotated. Each value is escaped once before parsing and decoded once by the validators. __str__ escapes it once on output, so the four test cases are consistent with the model code.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Nov 4, 2026
@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ceberam

ceberam commented Nov 13, 2026

Copy link
Copy Markdown
Member

@Fahmid-Arman Thanks a lot for suggesting this PR!
The main issue got accidentally fixed when reviewing a related PR #926
We would still acknowledge your contribution, at least with the test you proposed.
Could you please rebase your branch to the latest main?

Fahmid-Arman and others added 2 commits November 13, 2026 16:26
Signed-off-by: Fahmid Arman <fahmid.brac@gmail.com>
…t round trip

Revert the serializer to the state on main, where the escaping was already
added by docling-project#926, and keep the cases from the original change as parameters of
test_webvtt_export_keeps_text_literal.

Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
@ceberam
ceberam force-pushed the fix/webvtt-export-escaping branch from efaf556 to e65a82a Compare November 13, 2026 15:27
@github-actions github-actions Bot added ai:possible-duplicate AI triage: another PR may fix the same problem and removed ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Nov 13, 2026

@ceberam ceberam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fahmid-Arman To accelerate the process, I've just rebased, keeping the tests cases you added. All good to merge 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:possible-duplicate AI triage: another PR may fix the same problem bug Something isn't working media Images, audio, video, WebVTT, PDF shapes/widgets, MIME types, ImageRef serialization Output serializers: Markdown, HTML, LaTeX, JSON, plain-text, outline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebVTT export fails on cue text or voice names containing & or <

3 participants