Fix soft crash for edge emoji formatting (#4705)

This commit is contained in:
Elias Nahum
2020-08-20 14:48:48 -04:00
committed by GitHub
parent 3fce45f308
commit ea4e21de93
3 changed files with 16 additions and 2 deletions

View File

@@ -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 (
<View style={style.block}>{children}</View>
<View style={style.block}><Text>{children}</Text></View>
);
};

View File

@@ -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};

View File

@@ -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]]);