You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Send mentions and files back bare when rich text is edited - #1046
Editing a post that has an @mention or an image in it corrupts the post. Basecamp returns each mention and file attachment expanded, with an avatar or preview <figure> inside the <bc-attachment> and, for a mention, its rendered HTML in a content attribute. When an agent reads a post, changes some words and sends the content back, Basecamp stores that figure as content of its own. The figure breaks the paragraph around the mention apart, and every edit adds another copy.
richTextToHTML, which every rich-text write goes through, now reduces each <bc-attachment> that names a record (it has an sgid) to the bare tag that the rich text docs say to write. It drops the inner HTML and the content attribute and keeps the tag's other attributes, such as caption. This applies with --format html as well as with Markdown. In Markdown, an attachment written inside a code span or code block is left alone. An attachment without an sgid, such as a horizontal rule, carries its own content and is also left alone.
TestCommentsUpdateCollapsesAMentionCopiedFromTheAPI fails on main in both formats and passes with this change. New unit tests in internal/richtext/attachments_test.go cover file attributes, attachments without an sgid, and code in Markdown.
Tested against a local bc3: create a message with a mention, then edit it twice by sending back the content that messages show returned, once with --format html and once with Markdown.
Build
After the HTML edit
After the Markdown edit
v0.30.0
2 figures
3 figures, paragraph split in two
this branch
1 figure
1 figure, one paragraph
The same test with an uploaded image instead of a mention gave the same result on both builds: v0.30.0 corrupts the post and this branch keeps it intact. The image's attributes come through the edits unchanged.
bin/ci passes.
The root cause is on the server, which accepts the expanded form. A server-side fix would cover every API client, but this PR is limited to the CLI.
Summary by cubic
Fixes editing a post with an @mention or file attachment corrupting it by sending the bare <bc-attachment> tag back instead of the expanded form Basecamp returns.
richTextToHTML now reduces every <bc-attachment> naming a record to the write form Basecamp documents, in both HTML and Markdown. It drops the inner <figure> and content attribute but keeps others like caption and filename. Tags are read with an HTML tokenizer and the Markdown parser, so tags inside comments, code, backslash escapes, attribute values, or that are self-closing or unclosed are left as written. A new test covers a tag split across blockquote lines, which must be read from the parser's segments to keep each line's > out of the tag. Fixes#905.
Written for commit d3ed305. Summary will update on new commits.
Basecamp returns a mention or a file attachment expanded: the avatar or
preview as a <figure> inside the <bc-attachment>, and for a mention its
rendered HTML in a content attribute. An agent that edits a post by sending
back the content it read wrote that expanded form, which Basecamp stores
as content of its own: the figure breaks the paragraph around a mention
apart, and every edit adds another copy.
richTextToHTML now reduces every <bc-attachment> that names a record to
the bare tag Basecamp documents for writing one, in both formats. In
Markdown, attachments written inside code are left as they are.
Fixes#905
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Attachment parsing can silently delete intervening text and mentions after self-closing tags and corrupt attributes containing quoted greater-than characters.
This PR addresses #905 by normalizing expanded mentions and file attachments before rich-text writes, preventing repeated edits from duplicating previews or breaking paragraphs.
Changes:
Reduce attachments with an sgid to bare tags, removing rendered content while preserving other attributes.
Apply normalization to HTML and Markdown, preserving Markdown code and attachments without an sgid.
Add unit coverage and a comment-update regression test for both formats.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
File
Description
internal/richtext/attachments.go
Adds attachment normalization with Markdown code exclusions.
internal/richtext/attachments_test.go
Tests normalization, attribute preservation, and excluded content.
internal/commands/richtext_format.go
Integrates normalization into shared rich-text conversion.
internal/commands/richtext_format_test.go
Tests editing API-returned mentions in both formats.
A self-closing <bc-attachment/> was taken as the opening tag of the next
attachment, which dropped everything up to that one's closing tag. And the
first '>' was taken to end an opening tag even inside a quoted value. Walk
the tags instead of matching them with a pattern: skip quoted values, leave
self-closing and unclosed tags as written, and search a copy lowered only
in ASCII so its indexes stay those of the original.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Attachment collapsing misinterprets escaped Markdown tags and tags inside HTML comments as real elements, silently deleting literal text or visible content.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Escaped attachment tags are incorrectly collapsed
internal/richtext/attachments.go:39
Backslash-escaped attachment tags are literal Markdown, but only code spans and blocks are protected here. For example, Example: \<bc-attachment sgid="x">KEEP THIS TEXT\</bc-attachment> loses KEEP THIS TEXT and the closing tag's escape before Markdown conversion. Restrict collapsing to parser-recognized HTML, or exclude escaped tags while respecting Markdown context and odd/even backslash runs, and add a regression test.
Attachment tags inside HTML comments delete visible content
internal/richtext/attachments.go:93
The substring search treats attachment markup inside HTML comments as real elements. With --format html, <!-- <bc-attachment sgid="x"> --><p>KEEP THIS TEXT</p><!-- </bc-attachment> --> becomes <!-- <bc-attachment sgid="x"></bc-attachment> -->, silently deleting the visible paragraph. Skip comment contents when locating both opening and closing tags, preferably with HTML tokenization, and add a regression test.
A tag inside an HTML comment, or a Markdown tag escaped with a backslash,
is text rather than markup, but was read as an attachment, and collapsing
it deleted what lay between it and its closing tag. Pass both by when
looking for opening and closing tags.
Copilot's review of c203354 raised two cases in its summary, with no inline threads. Both are fixed in 8c49be3:
Escaped Markdown tags: a < after an odd run of backslashes is literal Markdown, so neither an escaped opening nor an escaped closing tag counts as markup (TestCollapseAttachmentsInMarkdownLeavesEscapedTags).
Tags inside HTML comments: comment contents, including an unterminated comment, are skipped when finding both opening and closing tags (TestCollapseAttachmentsLeavesTagsInComments).
Both tests fail on c203354 and pass now. bin/ci is green locally.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Attachment normalization can delete legitimate text by treating quoted attribute content and escaped HTML blocks as real attachment markup, and can leave preview markup behind.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Ignore attachment tags inside quoted HTML attributes
internal/richtext/attachments.go:149
Tag discovery treats attachment markup inside another tag's quoted attributes as real elements, so <span title='<bc-attachment sgid="x">'>KEEP THIS TEXT</span><span title='</bc-attachment>'>after</span> loses KEEP THIS TEXT and the intervening markup. A closing-tag string inside an image's alt attribute can also end a real attachment prematurely, leaving preview markup behind. Track surrounding tag and attribute boundaries before pairing attachment tags, and add regression tests for both cases.
Preserve attachments in escaped HTML blocks
internal/richtext/attachments.go:271
Only Markdown code nodes are protected, but renderHTMLBlock also renders unsupported HTML blocks entirely as escaped text (richtext.go:386–420). Consequently, Markdown input such as <section><bc-attachment sgid="x">KEEP THIS TEXT</bc-attachment></section> loses KEEP THIS TEXT before the renderer escapes the block, even though no attachment would have been emitted. Please also protect HTML blocks that the renderer will escape, so normalization only removes children of actual outgoing attachments.
A hand-rolled scan took attachment markup inside another tag's attribute
value for a tag, and in Markdown collapsed an attachment inside an HTML
block that the renderer shows as escaped text. Read HTML with x/net/html's
tokenizer, which already knows comments and quoted values, and in Markdown
take only the tags the renderer writes as markup: inline raw HTML and the
HTML blocks it passes through. Code, escapes and escaped blocks then need
no rules of their own.
Copilot's review of 8c49be3 raised two more cases in its summary: attachment markup inside another tag's attribute value, and attachments in Markdown HTML blocks that the renderer escapes. Instead of adding more rules to the hand-written scanner, cc072da finds tags the way the output is actually read:
HTML: golang.org/x/net/html's tokenizer (already a dependency), so comments, quoted attribute values and self-closing tags are handled as HTML handles them.
Markdown: only tags the renderer writes as markup, meaning inline raw HTML nodes and the HTML blocks renderHTMLBlock passes through. Code, backslash escapes and escaped HTML blocks hold no tags.
New tests TestCollapseAttachmentsIgnoresTagsInAttributeValues (including a </bc-attachment> in an alt) and TestCollapseAttachmentsInMarkdownLeavesEscapedHTMLBlocks fail on 8c49be3 and pass now. Every earlier test passes unchanged, and bin/ci is green locally.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Multiline attachment tags in blockquotes are parsed incorrectly, silently dropping content-type and caption attributes when blockquote prefixes are reintroduced.
A tag split across blockquote lines was read from the source between its
first and last segment, which put each line's "> " back, and the
tokenizer took that '>' for the tag's end. Tokenize the segments joined,
mapping each byte back to the source, and rebuild the tag from what was
read.
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
commandsCLI command implementationstestsTests (unit and e2e)
2 participants
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.
Editing a post that has an @mention or an image in it corrupts the post. Basecamp returns each mention and file attachment expanded, with an avatar or preview
<figure>inside the<bc-attachment>and, for a mention, its rendered HTML in acontentattribute. When an agent reads a post, changes some words and sends the content back, Basecamp stores that figure as content of its own. The figure breaks the paragraph around the mention apart, and every edit adds another copy.richTextToHTML, which every rich-text write goes through, now reduces each<bc-attachment>that names a record (it has ansgid) to the bare tag that the rich text docs say to write. It drops the inner HTML and thecontentattribute and keeps the tag's other attributes, such ascaption. This applies with--format htmlas well as with Markdown. In Markdown, an attachment written inside a code span or code block is left alone. An attachment without ansgid, such as a horizontal rule, carries its own content and is also left alone.Fixes #905
Verification
TestCommentsUpdateCollapsesAMentionCopiedFromTheAPIfails onmainin both formats and passes with this change. New unit tests ininternal/richtext/attachments_test.gocover file attributes, attachments without ansgid, and code in Markdown.contentthatmessages showreturned, once with--format htmland once with Markdown.The same test with an uploaded image instead of a mention gave the same result on both builds: v0.30.0 corrupts the post and this branch keeps it intact. The image's attributes come through the edits unchanged.
bin/cipasses.The root cause is on the server, which accepts the expanded form. A server-side fix would cover every API client, but this PR is limited to the CLI.
Summary by cubic
Fixes editing a post with an @mention or file attachment corrupting it by sending the bare
<bc-attachment>tag back instead of the expanded form Basecamp returns.richTextToHTMLnow reduces every<bc-attachment>naming a record to the write form Basecamp documents, in both HTML and Markdown. It drops the inner<figure>andcontentattribute but keeps others likecaptionandfilename. Tags are read with an HTML tokenizer and the Markdown parser, so tags inside comments, code, backslash escapes, attribute values, or that are self-closing or unclosed are left as written. A new test covers a tag split across blockquote lines, which must be read from the parser's segments to keep each line's>out of the tag. Fixes #905.Written for commit d3ed305. Summary will update on new commits.