Compare commits

...

2 Commits

Author SHA1 Message Date
Djorkaeff Alexandre 1239a28509
Merge branch 'develop' into fix.emoji-regex 2020-11-06 11:26:28 -03:00
Diego Mello 5beec1cd65 [FIX] Non-latin characters interpreted as emojis on markdown 2020-11-05 16:12:30 -03:00
5 changed files with 120 additions and 22 deletions

View File

@ -11188,6 +11188,104 @@ exports[`Storyshots Markdown list Markdown 1`] = `
/>
</View>
</Text>
<Text
style={
Array [
undefined,
Object {
"color": "#2f343d",
},
]
}
>
<Text
accessibilityLabel="🤙"
style={
Array [
Object {
"backgroundColor": "transparent",
"fontFamily": "System",
"fontSize": 16,
"fontWeight": "400",
},
Array [
Object {},
Object {
"alignItems": "flex-start",
"flexDirection": "row",
"flexWrap": "wrap",
"justifyContent": "flex-start",
"marginBottom": 0,
"marginTop": 0,
},
],
]
}
>
🤙
</Text>
<View
style={
Array [
Object {
"overflow": "hidden",
},
Array [
Object {
"height": 20,
"width": 20,
},
Object {},
],
]
}
>
<FastImageView
resizeMode="contain"
source={
Object {
"priority": "high",
"uri": "https://open.rocket.chat/emoji-custom/react_rocket.png",
}
}
style={
Object {
"bottom": 0,
"left": 0,
"position": "absolute",
"right": 0,
"top": 0,
}
}
/>
</View>
<Text
accessibilityLabel="ひ"
style={
Array [
Object {
"backgroundColor": "transparent",
"fontFamily": "System",
"fontSize": 16,
"fontWeight": "400",
},
Array [
Object {},
Object {
"alignItems": "flex-start",
"flexDirection": "row",
"flexWrap": "wrap",
"justifyContent": "flex-start",
"marginBottom": 0,
"marginTop": 0,
},
],
]
}
>
</Text>
</Text>
</View>
<Text
style={

View File

@ -4,6 +4,7 @@ import { Parser, Node } from 'commonmark';
import Renderer from 'commonmark-react-renderer';
import PropTypes from 'prop-types';
import removeMarkdown from 'remove-markdown';
import emojiRegex from 'emoji-regex/RGI_Emoji';
import shortnameToUnicode from '../../utils/shortnameToUnicode';
import I18n from '../../i18n';
@ -31,36 +32,22 @@ const formatText = text => text.replace(
);
const emojiRanges = [
'\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]', // unicode emoji from https://www.regextester.com/106421
emojiRegex(),
':.{1,40}:', // custom emoji
' |\n' // allow spaces and line breaks
].join('|');
const emojisRegex = new RegExp(emojiRanges, 'g');
const removeSpaces = str => str && str.replace(/\s/g, '');
const removeAllEmoji = str => str.replace(new RegExp(emojiRanges, 'g'), '');
const removeAllEmoji = str => str.replace(emojisRegex, '');
const emojiCount = str => str?.match(emojisRegex, '')?.length;
const isOnlyEmoji = (str) => {
str = removeSpaces(str);
return !removeAllEmoji(str).length;
};
const removeOneEmoji = str => str.replace(new RegExp(emojiRanges), '');
const emojiCount = (str) => {
str = removeSpaces(str);
let oldLength = 0;
let counter = 0;
while (oldLength !== str.length) {
oldLength = str.length;
str = removeOneEmoji(str);
if (oldLength !== str.length) {
counter += 1;
}
}
return counter;
return !removeAllEmoji(str).length && emojiCount(str) <= 3;
};
const parser = new Parser();
@ -395,7 +382,7 @@ class Markdown extends PureComponent {
let ast = parser.parse(m);
ast = mergeTextNodes(ast);
this.isMessageContainsOnlyEmoji = isOnlyEmoji(m) && emojiCount(m) <= 3;
this.isMessageContainsOnlyEmoji = isOnlyEmoji(m);
this.editedMessage(ast);
return this.renderer.render(ast);
}

View File

@ -49,6 +49,7 @@
"commonmark-react-renderer": "git+https://github.com/RocketChat/commonmark-react-renderer.git",
"deep-equal": "2.0.3",
"ejson": "2.2.0",
"emoji-regex": "^9.2.0",
"eslint-config-airbnb": "^18.1.0",
"expo-apple-authentication": "^2.2.1",
"expo-av": "8.2.1",

View File

@ -171,6 +171,13 @@ export default ({ theme }) => {
getCustomEmoji={getCustomEmoji}
baseUrl={baseUrl}
/>
{/* Emojis + non-latin characters */}
<Markdown
msg='🤙:react_rocket:ひ'
theme={theme}
getCustomEmoji={getCustomEmoji}
baseUrl={baseUrl}
/>
</View>
<StoriesSeparator style={styles.separator} title='Block Quote' theme={theme} />

View File

@ -6105,6 +6105,11 @@ emoji-regex@^9.0.0:
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.0.0.tgz#48a2309cc8a1d2e9d23bc6a67c39b63032e76ea4"
integrity sha512-6p1NII1Vm62wni/VR/cUMauVQoxmLVb9csqQlvLz+hO2gk8U2UYDfXHQSUYIBKmZwAKz867IDqG7B+u0mj+M6w==
emoji-regex@^9.2.0:
version "9.2.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.2.0.tgz#a26da8e832b16a9753309f25e35e3c0efb9a066a"
integrity sha512-DNc3KFPK18bPdElMJnf/Pkv5TXhxFU3YFDEuGLDRtPmV4rkmCjBkCSEp22u6rBHdSN9Vlp/GK7k98prmE1Jgug==
emojis-list@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"