Fix incorrect custom html crashing app (#429)
authorAjay Bura <ajbura@gmail.com>
Fri, 25 Mar 2022 05:07:35 +0000 (10:37 +0530)
committerAjay Bura <ajbura@gmail.com>
Fri, 25 Mar 2022 05:07:35 +0000 (10:37 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/app/molecules/message/Message.jsx

index f5e3e2b22dda9f04d55c3c0543f02eea8d4dc01e..5a906f0d3c7a7be34cd3a33ad993cca070cb9db6 100644 (file)
@@ -186,9 +186,17 @@ const MessageBody = React.memo(({
   // if body is not string it is a React element.
   if (typeof body !== 'string') return <div className="message__body">{body}</div>;
 
-  let content = isCustomHTML
-    ? twemojify(sanitizeCustomHtml(body), undefined, true, false)
-    : twemojify(body, undefined, true);
+  let content = null;
+  if (isCustomHTML) {
+    try {
+      content = twemojify(sanitizeCustomHtml(body), undefined, true, false);
+    } catch {
+      console.error('Malformed custom html: ', body);
+      content = twemojify(body, undefined);
+    }
+  } else {
+    content = twemojify(body, undefined, true);
+  }
 
   // Determine if this message should render with large emojis
   // Criteria: