summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2015-10-08 13:19:39 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2015-10-08 13:19:39 -0400
commit7dde0211c5276170bffb8d0e996ef2178f19f45c (patch)
treea07ed4c2eda57354867d7883756770b6277f5bb4
parent806fd77ec91cb899d159a235f2bb46e4363f3c12 (diff)
parentfa8a1ca0987cf2290be4bb3d57a55f3d8e24cd89 (diff)
downloadchat-7dde0211c5276170bffb8d0e996ef2178f19f45c.tar.gz
chat-7dde0211c5276170bffb8d0e996ef2178f19f45c.tar.bz2
chat-7dde0211c5276170bffb8d0e996ef2178f19f45c.zip
Merge pull request #982 from hmhealey/plt547
PLT-547 Changed emoticons so that they must be surrounded by whitespace
-rw-r--r--web/react/utils/emoticons.jsx48
1 files changed, 24 insertions, 24 deletions
diff --git a/web/react/utils/emoticons.jsx b/web/react/utils/emoticons.jsx
index a4f15796d..94bb91503 100644
--- a/web/react/utils/emoticons.jsx
+++ b/web/react/utils/emoticons.jsx
@@ -2,26 +2,26 @@
// See License.txt for license information.
const emoticonPatterns = {
- smile: /:-?\)/g, // :)
- open_mouth: /:o/gi, // :o
- scream: /:-o/gi, // :-o
- smirk: /:-?]/g, // :]
- grinning: /:-?d/gi, // :D
- stuck_out_tongue_closed_eyes: /x-d/gi, // x-d
- stuck_out_tongue_winking_eye: /:-?p/gi, // :p
- rage: /:-?[\[@]/g, // :@
- frowning: /:-?\(/g, // :(
- sob: /:['’]-?\(|:&#x27;\(/g, // :`(
- kissing_heart: /:-?\*/g, // :*
- pensive: /:-?\//g, // :/
- confounded: /:-?s/gi, // :s
- flushed: /:-?\|/g, // :|
- relaxed: /:-?\$/g, // :$
- mask: /:-x/gi, // :-x
- heart: /<3|&lt;3/g, // <3
- broken_heart: /<\/3|&lt;&#x2F;3/g, // </3
- thumbsup: /:\+1:/g, // :+1:
- thumbsdown: /:\-1:/g // :-1:
+ smile: /(^|\s)(:-?\))($|\s)/g, // :)
+ open_mouth: /(^|\s)(:o)($|\s)/gi, // :o
+ scream: /(^|\s)(:-o)($|\s)/gi, // :-o
+ smirk: /(^|\s)(:-?])($|\s)/g, // :]
+ grinning: /(^|\s)(:-?d)($|\s)/gi, // :D
+ stuck_out_tongue_closed_eyes: /(^|\s)(x-d)($|\s)/gi, // x-d
+ stuck_out_tongue: /(^|\s)(:-?p)($|\s)/gi, // :p
+ rage: /(^|\s)(:-?[\[@])($|\s)/g, // :@
+ frowning: /(^|\s)(:-?\()($|\s)/g, // :(
+ sob: /(^|\s)(:['’]-?\(|:&#x27;\(|:&#39;\()($|\s)/g, // :`(
+ kissing_heart: /(^|\s)(:-?\*)($|\s)/g, // :*
+ pensive: /(^|\s)(:-?\/)($|\s)/g, // :/
+ confounded: /(^|\s)(:-?s)($|\s)/gi, // :s
+ flushed: /(^|\s)(:-?\|)($|\s)/g, // :|
+ relaxed: /(^|\s)(:-?\$)($|\s)/g, // :$
+ mask: /(^|\s)(:-x)($|\s)/gi, // :-x
+ heart: /(^|\s)(<3|&lt;3)($|\s)/g, // <3
+ broken_heart: /(^|\s)(<\/3|&lt;&#x2F;3)($|\s)/g, // </3
+ thumbsup: /(^|\s)(:\+1:)($|\s)/g, // :+1:
+ thumbsdown: /(^|\s)(:\-1:)($|\s)/g // :-1:
};
function initializeEmoticonMap() {
@@ -126,7 +126,7 @@ const emoticonMap = initializeEmoticonMap();
export function handleEmoticons(text, tokens) {
let output = text;
- function replaceEmoticonWithToken(match, name) {
+ function replaceEmoticonWithToken(match, prefix, name, suffix) {
if (emoticonMap[name]) {
const index = tokens.size;
const alias = `MM_EMOTICON${index}`;
@@ -136,18 +136,18 @@ export function handleEmoticons(text, tokens) {
originalText: match
});
- return alias;
+ return prefix + alias + suffix;
}
return match;
}
- output = output.replace(/:([a-zA-Z0-9_-]+):/g, replaceEmoticonWithToken);
+ output = output.replace(/(^|\s):([a-zA-Z0-9_-]+):($|\s)/g, replaceEmoticonWithToken);
$.each(emoticonPatterns, (name, pattern) => {
// this might look a bit funny, but since the name isn't contained in the actual match
// like with the named emoticons, we need to add it in manually
- output = output.replace(pattern, (match) => replaceEmoticonWithToken(match, name));
+ output = output.replace(pattern, (match, prefix, emoticon, suffix) => replaceEmoticonWithToken(match, prefix, name, suffix));
});
return output;