Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose_paste: Avoid pasting URLs when pasting a single image.
apoorvapendse0374e386eced
diff --git a/web/src/compose_paste.ts b/web/src/compose_paste.tsindex 2a274155fa7..80b875d8db7 100644--- a/web/src/compose_paste.ts+++ b/web/src/compose_paste.ts@@ -208,9 +208,8 @@ export function is_single_image(paste_html: string): boolean {return (is_from_excel(html_fragment) ||is_from_libreoffice_calc(html_fragment) ||- (html_fragment.childNodes.length === 1 &&- html_fragment.firstElementChild !== null &&- html_fragment.firstElementChild.nodeName === "IMG")+ (html_fragment.querySelectorAll("img").length === 1 &&+ count_valid_text_nodes_upto([...html_fragment.childNodes], 1) === 0));}diff --git a/web/tests/compose_paste.test.cjs b/web/tests/compose_paste.test.cjsindex 12ada9821c0..b5cd1453a92 100644--- a/web/tests/compose_paste.test.cjs+++ b/web/tests/compose_paste.test.cjs@@ -314,6 +314,11 @@ run_test("paste_handler_converter", () => {input = `<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title></title><meta name="generator" content="LibreOffice 25.2.3.2 (Windows)"/><style type="text/css">@page { size: 8.5in 11in; margin: 0.79in }p { line-height: 115%; margin-bottom: 0.1in; background: transparent }</style></head><body lang="en-US" link="#000080" vlink="#800000" dir="ltr"><table width="258" cellpadding="2" cellspacing="0"><col width="83"/><col width="81"/><col width="81"/><tr valign="bottom"><td width="83" height="16" style="border: none; padding: 0in"><p align="left"><font face="Arial, serif">Melgar</font></p></td><td width="81" style="border: none; padding: 0in"><p align="left"><font face="Arial, serif">Female</font></p></td><td width="81" style="border: none; padding: 0in"><p align="left"><font face="Arial, serif">UnitedStates</font></p></td></tr><tr valign="bottom"><td width="83" height="16" style="border: none; padding: 0in"><p align="left"><font face="Arial, serif">Weiland</font></p></td><td width="81" style="border: none; padding: 0in"><p align="left"><font face="Arial, serif">Female</font></p></td><td width="81" style="border: none; padding: 0in"><p align="left"><font face="Arial, serif">UnitedStates</font></p></td></tr><tr valign="bottom"><td width="83" height="16" style="border: none; padding: 0in"><p align="left"><font face="Arial, serif">Winward</font></p></td><td width="81" style="border: none; padding: 0in"><p align="left"><font face="Arial, serif">Female</font></p></td><td width="81" style="border: none; padding: 0in"><p align="left"><font face="Arial, serif">GreatBritain</font></p></td></tr></table></body></html>`;assert.ok(compose_paste.is_single_image(input));+ // Copying an image and pasting it with `paste_html` containing other empty text nodes and+ // comment nodes should still classify the `paste_html` as an image that needs to be uploaded.+ input = `<html>\n<body>\n<!--StartFragment--><img src="http://zulip.zulipdev.com:9991/user_uploads/thumbnail/2/a0/wETeF-Yv2wmMM6289kO9VC0s/image.png/840x560.webp"/><!--EndFragment-->\n</body>\n</html>`;+ assert.ok(compose_paste.is_single_image(input));+// Pasting from the mac terminalinput ='<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="Content-Style-Type" content="text/css"><title></title><meta name="Generator" content="Cocoa HTML Writer"><meta name="CocoaVersion" content="2575.4"><style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}span.s1 {font-variant-ligatures: no-common-ligatures}</style></head><body><p class="p1"><span class="s1">insertions</span></p></body></html>';