Skip to content

[FIX] Escape special characters in WebVTT and SMPTE-TT output (#2437) - #2438

Open
Aditya-Saroha wants to merge 1 commit into
CCExtractor:masterfrom
Aditya-Saroha:fix/escape-webvtt-smptett
Open

Aditya-Saroha wants to merge 1 commit into
CCExtractor:masterfrom
Aditya-Saroha:fix/escape-webvtt-smptett

Conversation

@Aditya-Saroha

Copy link
Copy Markdown

In raising this pull request, I confirm the following (please check boxes):

Reason for this PR:

  • This PR adds new functionality.
  • This PR fixes a bug that I have personally experienced or that a real user has reported and for which a sample exists.
  • This PR is porting code from C to Rust.

Sanity check:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • If the PR adds new functionality, I've added it to the changelog. If it's just a bug fix, I have NOT added it to the changelog.
  • I am NOT adding new C code unless it's to fix an existing, reproducible bug.

Repro instructions:

Sample: markup.bin attached to issue #2437 (a 77-byte RCWT sample containing <BOB> & HI).

Commands to reproduce:

ccextractor markup.bin --out=webvtt -o markup.vtt
ccextractor markup.bin --out=smptett -o markup.xml
python3 -c 'import xml.etree.ElementTree as E; E.parse("markup.xml")'

Before fix:

  • WebVTT writes & HI unescaped. When parsed in a browser (e.g., Chromium cue.getCueAsHTML().textContent), is parsed as an unknown HTML element and omitted from text display, leaving only & HI.
  • SMPTE-TT writes & HI.... XML parsing fails with ParseError: not well-formed (invalid token): line 20, column 21 due to the unclosed tag and bare &.

After fix:

  • WebVTT escapes literal caption characters to & HI, preserving & HI as visible text in browser cues.
  • SMPTE-TT escapes literal characters in get_decoder_line_encoded(), producing valid XML that parses cleanly with xml.etree.ElementTree.
  • Formats without HTML/XML entity requirements (such as SRT, SSA, SAMI, SPUPNG) remain untouched, preservingraw text as decided in [FIX] escape special characters ( < > & ) to HTML context #1703.

Description of Changes

Fixes #2437.

  1. src/lib_ccx/ccx_encoders_webvtt.c:
  • In write_cc_buffer_as_webvtt(), escape literal caption characters (& -> &, < -> <, > -> >). Encoder-generated styling tags (, , <c.color>, , ) are written separately and remain unescaped.
  1. src/lib_ccx/ccx_encoders_helpers.c:
  • In get_decoder_line_encoded(), escape literal caption characters when ctx->write_format == CCX_OF_SMPTETT. Encoder formatting tags (, , ) are inserted separately and remain untouched, allowing write_cc_buffer_as_smptett() to convert them to TTML style tags while producing valid XML text.
  1. src/lib_ccx/ccx_encoders_smptett.c:
  • In write_cc_buffer_as_smptett(), updated strchr calls searching for # and > in font-colored blocks to search starting from start rather than context->subline, avoiding premature matches if text preceding the tag contains # or >.

Verification

  • Verified SMPTE-TT XML parses cleanly via python3 -c "import xml.etree.ElementTree as E; E.parse('...')" with exit code 0 and text & HI.
  • Verified WebVTT cue payload decodes properly in Chromium (VTTCue.getCueAsHTML().textContent gives & HI).
  • Verified styled captions (, , color tags) retain formatting elements while escaping inner special characters.
  • Verified SRT output remains unescaped (regression check).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Unescaped caption text breaks WebVTT and SMPTE-TT output

1 participant