From ea4e21de93c587ee3fff7f5124f230e4fe214ed6 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Thu, 20 Aug 2020 14:48:48 -0400 Subject: [PATCH] Fix soft crash for edge emoji formatting (#4705) --- .../markdown/markdown_emoji/markdown_emoji.js | 3 ++- app/utils/emoji_utils.js | 2 +- app/utils/emoji_utils.test.js | 13 +++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/components/markdown/markdown_emoji/markdown_emoji.js b/app/components/markdown/markdown_emoji/markdown_emoji.js index a8aa43ba9c..22dd9cbe4f 100644 --- a/app/components/markdown/markdown_emoji/markdown_emoji.js +++ b/app/components/markdown/markdown_emoji/markdown_emoji.js @@ -38,6 +38,7 @@ export default class MarkdownEmoji extends PureComponent { editedIndicator: this.renderEditedIndicator, emoji: this.renderEmoji, paragraph: this.renderParagraph, + document: this.renderParagraph, text: this.renderText, }, }); @@ -66,7 +67,7 @@ export default class MarkdownEmoji extends PureComponent { renderParagraph = ({children}) => { const style = getStyleSheet(this.props.theme); return ( - {children} + {children} ); }; diff --git a/app/utils/emoji_utils.js b/app/utils/emoji_utils.js index ae092d11b9..46433b07eb 100644 --- a/app/utils/emoji_utils.js +++ b/app/utils/emoji_utils.js @@ -55,7 +55,7 @@ export function hasEmojisOnly(message, customEmojis) { return {isEmojiOnly: false, shouldRenderJumboEmoji: false}; } - const chunks = message.trim().split(' ').filter((m) => m && m.length > 0); + const chunks = message.trim().replace(/\n/g, ' ').split(' ').filter((m) => m && m.length > 0); if (chunks.length === 0) { return {isEmojiOnly: false, shouldRenderJumboEmoji: false}; diff --git a/app/utils/emoji_utils.test.js b/app/utils/emoji_utils.test.js index 052dc434cb..6eb60085fa 100644 --- a/app/utils/emoji_utils.test.js +++ b/app/utils/emoji_utils.test.js @@ -64,6 +64,19 @@ describe('hasEmojisOnly with named emojis', () => { name: 'This should render a codeblock instead', message: ' :D', expected: {isEmojiOnly: false, shouldRenderJumboEmoji: false}, + }, { + name: 'Mixed emojis with whitespace and newlines', + message: `:fire: + :-)`, + expected: {isEmojiOnly: true, shouldRenderJumboEmoji: true}, + }, { + name: 'Emojis with whitespace and newlines', + message: ':fire: \n:smile:', + expected: {isEmojiOnly: true, shouldRenderJumboEmoji: true}, + }, { + name: 'Emojis with newlines', + message: ':fire:\n:smile:', + expected: {isEmojiOnly: true, shouldRenderJumboEmoji: true}, }]; const customEmojis = new Map([['valid_custom', 0]]);