Skip to content

Commit 8230222

Browse files
ravarora2BuzzPRReviewAssistant1
andauthored
AIDA-2425: Preserve links beside pasted images (#2520)
## Why Pasting a sentence with an inline image could drop every labelled link. Buzz discarded image alt text, then rejected the HTML because it no longer matched the clipboard's plain text. Related: [AIDA-2425](https://linear.app/squareup/issue/AIDA-2425). This fixes the reproduced inline-image case; the original Slack report still needs its own clipboard capture. ## What Keep image alt text and safe link destinations when pasting external HTML. Keep plain-text paste, the text-match guard, and URL filtering unchanged. ## How Replace images with text nodes before stripping HTML attributes in the existing external-paste converter. Cover images beside links, images inside labels, empty alt text, unsafe destinations, mismatched text, and undo. ## Risk This changes external HTML paste in the shared composer. Clipboards whose text still differs fall back to plain text. No image loading or attachment behavior is added. ## Testing Independent review of `a7fb6366e3f93b92a62fea9c5e657f2e9efd8abf` found no blocking correctness or security issue. Final head `4eba754c5d05fbde15eaf0f09cd188ec44116aff` rebases onto `b621738454064985fe42de0c077e8d381ca0037b`. The only conflict was adjacent help-guide additions; both the upstream `/leave` instructions and paste guidance are retained. Paste implementation and tests are unchanged from the reviewed commit. Opened [the sample page](https://buzz.block.builderlab.xyz/media/59bc1610cb9bd97da4ce9bb95c301be2134f0c43a2aca6b8267db3e58b303123.html) in Chromium on macOS. Copied each sample, pressed ordinary ⌘V in the actual composer, and sent each draft through the fixture relay. Both kept the labelled URL; the image sample kept `:wave:`. The independent reviewer repeated this successfully at the rebased commit. Browser cases added/removed: 0/0. The existing external-link journey includes an inline image and checks the composer and published message. The independent reviewer ran the complete paste file on the rebased commit: 8 passed, 2 existing platform skips across Chromium and WebKit. The case matrix stays in the mounted editor tests. All mandatory push hooks passed at `a7fb6366e` after rerunning with one test worker. Following the author's request to push, the final documentation-conflict rebase skipped the long TypeScript/related-test lane; design and push-policy hooks still passed. Current-head CI is pending. Validation limits: the first rebased push-hook run failed 9 tests across retained-page, ChannelsPage.conversion, useConversationTabs.panels, huddle/composer, and MessageEdit.integration. Most failures were timeouts; their cause is unverified. A separate exploratory full frontend run was interrupted after reporting three agent-service failures and one MessageComposer timeout, so it is not a completed full-suite result. Earlier full-suite failures and old-head CI failures are not established baseline defects. Installed Tauri, Slack Desktop, and human acceptance remain unverified. Generated with Codex Signed-off-by: Ravneet Arora <[email protected]> Co-authored-by: BuzzPRReviewAssistant1 <a581a7e8115222acdc32ffb14bfce55d48c24478d98e155f8eba126b69b83c7b@buzz.block.builderlab.xyz>
1 parent fb90c66 commit 8230222

4 files changed

Lines changed: 64 additions & 4 deletions

File tree

‎docs/buzz-help.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ that agent in Buzz; they do not notify the external app through this connection.
274274
or are removed in People.
275275
- In a channel, typing `/leave` by itself opens the same **Leave channel**
276276
confirmation. The command is not posted as a message.
277+
- **Pasted web links** keep their labels when the clipboard's HTML and plain
278+
text agree, including image alt text. Use ordinary paste; plain-text paste
279+
uses only the clipboard's plain text.
277280
- **Long text pastes** that exceed the message limit show an error and leave
278281
your draft unchanged. Shorten the text, or save it as a text file and use
279282
**Attach files** where uploads are available.

‎src/features/messages/EditableInput.test.tsx‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4610,6 +4610,57 @@ it.each([
46104610
[
46114611
"Ship 🚀 guide",
46124612
'Ship <img data-stringify-type="emoji" alt="🚀"> <a href="https://example.com">guide</a>',
4613+
"Ship 🚀 [guide](https://example.com/)",
4614+
],
4615+
[
4616+
"Hello :wave: Review the pull request",
4617+
'Hello <img alt=":wave:" src="https://example.com/emoji.png"> Review <a href="https://example.com/review">the pull request</a>',
4618+
"Hello :wave: Review [the pull request](https://example.com/review)",
4619+
],
4620+
[
4621+
"Read 🚀 guide",
4622+
'Read <a href="https://example.com"><img alt="🚀"> guide</a>',
4623+
"Read [🚀 guide](https://example.com/)",
4624+
],
4625+
[
4626+
"Read 🚀",
4627+
'Read <a href="https://example.com"><img alt="🚀"></a>',
4628+
"Read [🚀](https://example.com/)",
4629+
],
4630+
[
4631+
"Read guide",
4632+
'Read <img src="https://example.com/image.png"><img alt=""> <a href="https://example.com">guide</a>',
4633+
"Read [guide](https://example.com/)",
4634+
],
4635+
[
4636+
"Read <img src=x onerror=alert(1)> guide",
4637+
'Read <img alt="&lt;img src=x onerror=alert(1)&gt;"> <a href="https://example.com">guide</a>',
4638+
"Read <img src=x onerror=alert(1)> [guide](https://example.com/)",
4639+
],
4640+
])(
4641+
"preserves image alt text and safe external links: %s",
4642+
(plain, html, expected) => {
4643+
const h = mount();
4644+
paste(h.input, plain, html);
4645+
expect(h.markdown()).toBe(expected);
4646+
expect(h.input.querySelector("img")).toBeNull();
4647+
act(() => h.input.undo(false));
4648+
expect(h.markdown()).toBe("");
4649+
},
4650+
);
4651+
4652+
it.each([
4653+
[
4654+
"Ship 🚀 guide",
4655+
'Ship <img alt="different"> <a href="https://example.com">guide</a>',
4656+
],
4657+
[
4658+
"Read guide",
4659+
'Read <img alt="extra"> <a href="https://example.com">guide</a>',
4660+
],
4661+
[
4662+
"Ship 🚀 guide",
4663+
'Ship <img alt="🚀" onerror="alert(1)"> <a href="javascript:alert(1)">guide</a>',
46134664
],
46144665
[
46154666
"guide",

‎src/features/messages/composer-clipboard.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ export function externalLinkMarkdown(
203203
"script, style, template, iframe, object, hr, input",
204204
))
205205
node.remove();
206+
// Browser text/plain can include an inline image's alt text. Preserve it as
207+
// literal text before stripping attributes, including inside link labels.
208+
for (const image of body.querySelectorAll("img"))
209+
image.replaceWith(
210+
body.ownerDocument.createTextNode(image.getAttribute("alt") ?? ""),
211+
);
206212
let linked = false;
207213
for (const element of body.querySelectorAll("*")) {
208214
const href =

‎tests/browser/composer-paste.spec.mjs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,18 @@ test("external linked text stays linked in the composer and sent message", async
298298
});
299299
await input.click();
300300
await pasteInto(input, {
301-
text: "Read the guide",
302-
html: '<p>Read <a href="https://example.com/guide">the guide</a></p>',
301+
text: "Read :wave: the guide",
302+
html: '<p>Read <img alt=":wave:" src="https://example.com/emoji.png"> <a href="https://example.com/guide">the guide</a></p>',
303303
});
304304
await expect(input).toHaveJSProperty(
305305
"value",
306-
"Read [the guide](https://example.com/guide)",
306+
"Read :wave: [the guide](https://example.com/guide)",
307307
);
308308
await expect(input.locator("[data-link-renderer]")).toHaveText("the guide");
309309
await input.press("Enter");
310310
await expect.poll(() => app.report.publications.length).toBe(1);
311311
expect(app.report.publications[0].event.content).toBe(
312-
"Read [the guide](https://example.com/guide)",
312+
"Read :wave: [the guide](https://example.com/guide)",
313313
);
314314
});
315315

0 commit comments

Comments
 (0)