fix regex shortcode problem

This commit is contained in:
Henry Jameson 2019-09-30 23:45:03 +03:00
parent aadd36f3ec
commit a2923570c3
2 changed files with 14 additions and 1 deletions

View file

@ -196,9 +196,11 @@ export const parseAttachment = (data) => {
return output
}
export const addEmojis = (string, emojis) => {
const matchOperatorsRegex = /[|\\{}()[\]^$+*?.-]/g
return emojis.reduce((acc, emoji) => {
const regexSafeShortCode = emoji.shortcode.replace(matchOperatorsRegex, '\\$&')
return acc.replace(
new RegExp(`:${emoji.shortcode}:`, 'g'),
new RegExp(`:${regexSafeShortCode}:`, 'g'),
`<img src='${emoji.url}' alt='${emoji.shortcode}' title='${emoji.shortcode}' class='emoji' />`
)
}, string)