From b662678f210ba893a2bb2c27ba781b2bf3ccfc16 Mon Sep 17 00:00:00 2001 From: BannerBomb Date: Sat, 17 Aug 2019 12:07:58 -0400 Subject: [PATCH] feat/fix(Util): fix animated part of parseEmoji regex and make id optional (#3407) * Small changes to parseEmoji regex I just made a small change to the parseEmoji regex, this change will make an invalid emoji, like `` return as null, before this change it would return as an animated emoji because the name started with an `a` which would result in false positives, then the `?` I added to the end of `(\d{17,19})?` is used if someone provided an emoji as `:name:` or `a:name:` it will return the correct values but have an invalid id. * Update Util.js 2nd Update: I changed the regex to output the results if you provide `` and <:aemoji:123456789012345678>` which will output `{ animated: false, name: "aemoji", id: "123456789012345678" }` or `<:emojiname:>` which outputs `{ animated: false, name: "emojiname", id: null }` or `` which would output `{ animated: true, name: "emoji", id: null }`. Before this PR the method would return that the emoji was animated if you provided something like `` because the name started with an `a`. --- src/util/Util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/Util.js b/src/util/Util.js index f9aaf21c2..8e6743d9f 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -244,9 +244,9 @@ class Util { static parseEmoji(text) { if (text.includes('%')) text = decodeURIComponent(text); if (!text.includes(':')) return { animated: false, name: text, id: null }; - const m = text.match(/?/); + const m = text.match(/?/); if (!m) return null; - return { animated: Boolean(m[1]), name: m[2], id: m[3] }; + return { animated: Boolean(m[1]), name: m[2], id: m[3] || null }; } /**