Skip to content

Commit d188b35

Browse files
committed
Again: Replace emoji-plugin regex
The Regex introduced in the last commit[1], was already working quite good. But still resulted in false positives for all URL that contained a second `:`. To fix this once and for all, we craft a simple, but long regex based on all emoji names and use this to match them. We could probably optimize it, but that should also be something the regex engine itself can and should do. [1]: 7e45533 (in this source tree) Signed-off-by: Sheogorath <[email protected]>
1 parent 7e45533 commit d188b35

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

public/js/extra.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,15 +1147,14 @@ const pdfPlugin = new Plugin(
11471147

11481148
const emojijsPlugin = new Plugin(
11491149
// regexp to match emoji shortcodes :something:
1150-
/:([^\s:]+):/,
1150+
// We generate an universal regex that guaranteed only contains the
1151+
// emojies we have available. This should prevent all false-positives
1152+
new RegExp(':(' + window.emojify.emojiNames.map((item) => { return RegExp.escape(item) }).join('|') + '):', 'i'),
11511153

11521154
(match, utils) => {
1153-
const emoji = match[1] ? match[1].toLowerCase() : undefined
1154-
if (window.emojify.emojiNames.includes(emoji)) {
1155-
const div = $(`<img class="emoji" src="${serverurl}/build/emojify.js/dist/images/basic/${emoji}.png"></img>`)
1156-
return div[0].outerHTML
1157-
}
1158-
return match[0]
1155+
const emoji = match[1].toLowerCase()
1156+
const div = $(`<img class="emoji" src="${serverurl}/build/emojify.js/dist/images/basic/${emoji}.png"></img>`)
1157+
return div[0].outerHTML
11591158
}
11601159
)
11611160

0 commit comments

Comments
 (0)