Remove block markers as nodes so <style>/raw-text content isn't corrupted - #1357
Remove block markers as nodes so <style>/raw-text content isn't corrupted#1357jeremy wants to merge 1 commit into
Conversation
Serialization stripped Trix's <!--block--> boundary markers with a context-free string replace over the already-serialized HTML. That replace can't tell Trix's own comment nodes from the identical byte sequence living in a text node, so it silently mangles benign content: <style>x<!--block-->y</style> serializes as <style>xy</style>. Inside a raw-text element it can also fuse otherwise-inert text into real markup. Walk the serializable element for comment nodes and remove only Trix's own 'block' markers, leaving text content untouched.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🟢 Approved
The structural fix is correct, safely scoped to working copies, and adequately covered by regression tests.
Pull request overview
Replaces unsafe serialized-string marker removal with structural comment-node removal, preserving raw-text content.
Changes:
- Removes only
blockcomment nodes viaTreeWalker. - Adds regression tests for marker removal and raw-text preservation.
- Regenerates the Action Text bundle.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
File summaries
| File | Description |
|---|---|
src/trix/core/serialization.js |
Structurally removes block markers. |
src/test/unit/serialization_test.js |
Covers comments and raw-text edge cases. |
action_text-trix/app/assets/javascripts/trix.js |
Updates the vendored bundle. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Problem
serializeToContentType(..., "text/html")strips Trix's<!--block-->boundary markers with a context-free global string replace over the already-serialized HTML:That replace can't distinguish Trix's own comment nodes (created in
BlockViewviadocument.createComment("block")) from the identical byte sequence<!--block-->sitting in a text node. So it corrupts content that merely happens to contain those bytes.The clearest case is a raw-text element like
<style>, whose contents are text, not parsed markup:<style>x<!--block-->y</style>serializes to<style>xy</style>— the inner text is silently mangled.</st<!--block-->yle>(one inert text node) collapses into a real</style>end tag that wasn't in the sanitized DOM.Fix
Remove the markers structurally, as comment nodes, instead of as text. Walk the serializable element for comment nodes and remove exactly Trix's own
blockmarkers:elementhere is always the serializer's own working copy — acloneNode(true)of the input element, or a freshlyDocumentView.rendered tree — never the live editor DOM, so mutating it in place is safe. The now-unusedblockCommentPatternconstant is removed.Tests
Added regression coverage in
serialization_test.js:<!--block-->byte sequence in a<style>text node round-trips verbatim (it's not a comment node, so it must be preserved).</st<!--block-->yle>shape does not splice into a real</style>end tag — the serialized value re-parses to the same single<style>element with intact text.<!--block-->comment nodes are still removed (existing behavior), and non-blockcomment nodes are left alone.The two corruption tests fail against the old string-replace implementation and pass with this change. Full suite green locally; the vendored Action Text bundle is regenerated via
yarn build.