fix: use JSON.stringify for caption text escaping in generated JS#625
Open
hobostay wants to merge 1 commit intoheygen-com:mainfrom
Open
fix: use JSON.stringify for caption text escaping in generated JS#625hobostay wants to merge 1 commit intoheygen-com:mainfrom
hobostay wants to merge 1 commit intoheygen-com:mainfrom
Conversation
The generated JavaScript used manual single-quote escaping (replace(/\\/g, '\\\\').replace(/'/g, \"'\\\\''\")) which missed newlines, carriage returns, and other special characters. Captions containing line breaks would produce syntactically broken JS. Use JSON.stringify which handles all JS string special characters correctly, including newlines, unicode, and control characters. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
jrusso1020
approved these changes
May 5, 2026
Collaborator
jrusso1020
left a comment
There was a problem hiding this comment.
Verified — generator.ts:306 only handles \\ and ', so a caption segment with a literal newline (or a U+2028/U+2029) emits broken JS. Switching to JSON.stringify is the right call: it returns a complete double-quoted JS string literal that handles all control chars and line separators, and the surrounding quotes are correctly removed at the call sites. LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
JSON.stringify()in caption JS generationDetails
Affected file:
packages/studio/src/captions/generator.ts(lines 306-313)A caption segment containing a literal newline (e.g. from a multiline caption) would produce broken JS like:
JSON.stringifyhandles all special characters correctly and produces a double-quoted string literal that is always valid JS.Test plan
🤖 Generated with Claude Code