fix(desktop): prevent injectTitle from expanding JS replacement patterns in titles - #6891
fix(desktop): prevent injectTitle from expanding JS replacement patterns in titles#6891xxiaoxiong wants to merge 1 commit into
Conversation
|
Hey @xxiaoxiong — thanks for jumping on this export-title bug so quickly. The scope here is nice and tight. Two quick things before reviewer pickup:
|
|
🧪 Queued for QA validation — this PR changes exported artifact/PDF behavior, so it needs a manual QA pass before merge. Nothing needed from you right now; we’ll update here once validation is done. Thanks for the contribution! |
nettee
left a comment
There was a problem hiding this comment.
I reviewed both desktop export title-replacement branches and verified that the callback form now preserves literal replacement-pattern characters while leaving the existing insertion paths unchanged. A focused Node check covered $$, $&,
|
Review and CI are both green now, so this is queued for manual QA validation before merge. Also, when you have a moment, please fill in the missing PR-body pieces: Surface area, Bug fix verification, and Validation. |
f8c0d7c to
936fd1f
Compare
Summary
Fix PDF/artifact export bug where titles containing characters with special meaning to JavaScript's$&, $
String.prototype.replace()(e.g. $$,, $') got corrupted when the source HTML already contained a<title>` element to be replaced.Root cause
apps/desktop/src/main/pdf-export.tsandapps/desktop/src/main/artifact-export.tsboth calldoc.replace(regex, tag)to overwrite an existing<title>...</title>block. The replacement stringtagwas passed directly as a string, which means JS interprets $$,, $', $<digits> as backreferences. A title likeSave $$ This Quarterwas silently stripped toSave $$ This Quarter, andRock $'n Roll Tour` produced broken HTML because the$'replacement inserted the portion of the string after the match.Repro
After many titles, this corrupts PDF metadata, breaks browser tab titles, and on
artifact-export.tscorrupts$titles.Fix
Wrap the replacement in an arrow function so the replacement string is treated literally instead of as a pattern:
The other two
replacecalls in these helpers already use replacer functions, so the bug only affects the title branch.Tests
Verified locally with a Node script (
String.replace) that titles containing$$,$&,$``,$'round-trip throughinjectTitle` after the fix. The desktop project has no existing unit-test harness for these helpers; this PR is a minimal targeted fix following the repo's typical scope (no tests added to avoid bloating the change).Fixes #6795