From 847acff894651b9a8c44e812b5093f596cd26cd8 Mon Sep 17 00:00:00 2001
From: David Baker <dave@matrix.org>
Date: Thu, 10 Oct 2019 17:36:22 +0100
Subject: [PATCH] Add some type checking on event body

---
 src/HtmlUtils.js | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/HtmlUtils.js b/src/HtmlUtils.js
index 7a212b2497..2266522bfe 100644
--- a/src/HtmlUtils.js
+++ b/src/HtmlUtils.js
@@ -412,11 +412,13 @@ export function bodyToHtml(content, highlights, opts={}) {
             };
         }
 
-        let formattedBody = content.formatted_body;
-        if (opts.stripReplyFallback && formattedBody) formattedBody = ReplyThread.stripHTMLReply(formattedBody);
-        strippedBody = opts.stripReplyFallback ? ReplyThread.stripPlainReply(content.body) : content.body;
+        let formattedBody = typeof content.formatted_body === 'string' ? content.formatted_body : null;
+        const plainBody = typeof content.body === 'string' ? content.body : null;
 
-        bodyHasEmoji = mightContainEmoji(isHtmlMessage ? formattedBody : content.body);
+        if (opts.stripReplyFallback && formattedBody) formattedBody = ReplyThread.stripHTMLReply(formattedBody);
+        strippedBody = opts.stripReplyFallback ? ReplyThread.stripPlainReply(plainBody) : plainBody;
+
+        bodyHasEmoji = mightContainEmoji(isHtmlMessage ? formattedBody : plainBody);
 
         // Only generate safeBody if the message was sent as org.matrix.custom.html
         if (isHtmlMessage) {