Repository navigation
Description
Describe the bug
Importing replacement transcript words can break a valid existing caption script while transcribe still returns exit 0 and ok: true. This happens when an old caption contains ];, for example a programming screencast caption items[i];.
Minimal reproduction
From a dependency-ready checkout of main 886e8696dfc43d748a221adf51678fc99d4ca74a, create these files in a directory named caption-repro:
captions.html:
<script>
const TRANSCRIPT = [{"id":"w0","text":"items[i];","start":0,"end":1}];
globalThis.captionWords = TRANSCRIPT;
</script>input.json:
[{"id":"w0","text":"Replacement caption","start":0,"end":1}]Run:
bun packages/cli/src/cli.ts transcribe caption-repro/input.json --dir caption-repro --jsonInspect the rewritten captions.html. The same problem occurs with const script instead of const TRANSCRIPT.
Expected behavior
Replace the entire old caption array, preserve the following JavaScript, and leave a valid script containing the new words.
Actual behavior
The array-matching regex stops at ]; inside the old word string. It replaces only that prefix and leaves the rest of the old array after the new one. Compiling the output with node:vm's Script throws SyntaxError: Unexpected identifier 'start'. Both supported variable names reproduce. The original script compiles.
| Same input | Main | Focused fix |
|---|---|---|
| CLI result | Exit 0, ok: true |
Exit 0, ok: true |
| Rewritten script | Invalid JavaScript, old array suffix remains | Valid JavaScript, complete replacement |
| Following caption code | Left after corrupted data | Preserved |
Environment
Current source main 886e8696d, package version 0.8.191. Linux x86_64, Node 26.11.1, Bun 1.4.1. The repository pins Bun 1.4.4; no version-dependent parser behavior is assumed. The real source CLI was invoked and its output compiled, without running transcription inference or playing media.
Additional context
The cause is patchCaptionHtml in packages/cli/src/whisper/normalize.ts. This is the CLI write path. Issue #3852 and merged PR #3896 cover the separate Studio read path. PR #5226 fixes script escaping and replacement-token handling, which does not fix this existing-array boundary.
Public issues, PRs, comments and related work were checked before filing. A focused fix and two regression cases are prepared.
Activity