From b467d0700f13fc53dad9cdb8b910124c983b35ff Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 6 Jul 2023 09:22:43 +0100 Subject: [PATCH] Replace brittle custom function with lodash implementation (#11188) --- src/utils/MessageDiffUtils.tsx | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/utils/MessageDiffUtils.tsx b/src/utils/MessageDiffUtils.tsx index 6d261052fd..04167ccddd 100644 --- a/src/utils/MessageDiffUtils.tsx +++ b/src/utils/MessageDiffUtils.tsx @@ -20,20 +20,10 @@ import { diff_match_patch as DiffMatchPatch } from "diff-match-patch"; import { DiffDOM, IDiff } from "diff-dom"; import { IContent } from "matrix-js-sdk/src/models/event"; import { logger } from "matrix-js-sdk/src/logger"; +import { unescape } from "lodash"; import { bodyToHtml, checkBlockNode, IOptsReturnString } from "../HtmlUtils"; -const decodeEntities = (function () { - let textarea: HTMLTextAreaElement | undefined; - return function (str: string): string { - if (!textarea) { - textarea = document.createElement("textarea"); - } - textarea.innerHTML = str; - return textarea.value; - }; -})(); - function textToHtml(text: string): string { const container = document.createElement("div"); container.textContent = text; @@ -153,7 +143,7 @@ function adjustRoutes(diff: IDiff, remainingDiffs: IDiff[]): void { } function stringAsTextNode(string: string): Text { - return document.createTextNode(decodeEntities(string)); + return document.createTextNode(unescape(string)); } function renderDifferenceInDOM(originalRootNode: Node, diff: IDiff, diffMathPatch: DiffMatchPatch): void {