Skip to content

Commit 7192bac

Browse files
authored
[CLNP-4962] fix: prevent HTML entity conversion by using insertText in document.execCommand (#1208)
Fixes the issue https://sendbird.atlassian.net/browse/CLNP-4962 where HTML entities like `&sect` or `&lt` were being automatically converted to their corresponding symbols (§ or >) when pasting content into a contentEditable element. ### Changes The `document.execCommand('insertHTML', false, sanitizeString(text))` command was replaced with `document.execCommand('insertText', false, sanitizeString(text))`. This change ensures that HTML entities are inserted as plain text rather than being interpreted and converted by the browser. Now it prevents unintended conversion of HTML entities, maintaining the original text as expected when pasting content. ### How to test? Try this on the preview. Type `&sect` and copy & paste the text to the input box. The exact same text(=`&sect`) should be on the input not `§`.
1 parent d0eb89d commit 7192bac

File tree

1 file changed

+2
-2
lines changed
  • src/ui/MessageInput/hooks/usePaste

1 file changed

+2
-2
lines changed

src/ui/MessageInput/hooks/usePaste/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function usePaste({
2727
// simple text, continue as normal
2828
if (!html) {
2929
const text = e.clipboardData.getData('text') || getURIListText(e);
30-
document.execCommand('insertHTML', false, sanitizeString(text));
30+
document.execCommand('insertText', false, sanitizeString(text));
3131
setIsInput(true);
3232
setHeight();
3333
return;
@@ -43,7 +43,7 @@ export function usePaste({
4343
if (!hasMention(pasteNode)) {
4444
// to preserve space between words
4545
const text = extractTextFromNodes(Array.from(pasteNode.children) as HTMLSpanElement[]);
46-
document.execCommand('insertHTML', false, sanitizeString(text));
46+
document.execCommand('insertText', false, sanitizeString(text));
4747
pasteNode.remove();
4848
setIsInput(true);
4949
setHeight();

0 commit comments

Comments
 (0)