Fixed degraded dirty emote code escaping (#3010)

This commit is contained in:
Paweł 2021-07-17 12:35:43 +02:00 committed by GitHub
parent 6022cd86eb
commit a509c7514c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 42 deletions

View file

@ -2,6 +2,8 @@
## Unversioned ## Unversioned
- Bugfix: Fixed "smiley" emotes being unable to be "Tabbed" with autocompletion, introduced in v2.3.3. (#3010)
## 2.3.3 ## 2.3.3
- Major: Added username autocompletion popup menu when typing usernames with an @ prefix. (#1979, #2866) - Major: Added username autocompletion popup menu when typing usernames with an @ prefix. (#1979, #2866)

View file

@ -111,7 +111,7 @@ void ImageLayoutElement::addCopyTextToString(QString &str, int from,
if (emoteElement) if (emoteElement)
{ {
str += emoteElement->getEmote()->getCopyString(); str += emoteElement->getEmote()->getCopyString();
str = TwitchEmotes::cleanUpEmoteCode(EmoteName{str}); str = TwitchEmotes::cleanUpEmoteCode(str);
if (this->hasTrailingSpace()) if (this->hasTrailingSpace())
{ {
str += " "; str += " ";

View file

@ -240,12 +240,10 @@ void TwitchAccount::loadEmotes()
KrakenEmote krakenEmote(emoteArrObj.toObject()); KrakenEmote krakenEmote(emoteArrObj.toObject());
auto id = EmoteId{krakenEmote.id}; auto id = EmoteId{krakenEmote.id};
auto code = EmoteName{krakenEmote.code}; auto code = EmoteName{
TwitchEmotes::cleanUpEmoteCode(krakenEmote.code)};
auto cleanCode = emoteSet->emotes.emplace_back(TwitchEmote{id, code});
EmoteName{TwitchEmotes::cleanUpEmoteCode(code)};
emoteSet->emotes.emplace_back(
TwitchEmote{id, cleanCode});
if (!emoteSet->local) if (!emoteSet->local)
{ {
@ -370,11 +368,11 @@ void TwitchAccount::loadUserstateEmotes()
IvrEmote ivrEmote(emoteObj.toObject()); IvrEmote ivrEmote(emoteObj.toObject());
auto id = EmoteId{ivrEmote.id}; auto id = EmoteId{ivrEmote.id};
auto code = EmoteName{ivrEmote.code}; auto code = EmoteName{
auto cleanCode = TwitchEmotes::cleanUpEmoteCode(ivrEmote.code)};
EmoteName{TwitchEmotes::cleanUpEmoteCode(code)};
newUserEmoteSet->emotes.push_back( newUserEmoteSet->emotes.push_back(
TwitchEmote{id, cleanCode}); TwitchEmote{id, code});
auto emote = auto emote =
getApp()->emotes->twitch.getOrCreateEmote(id, code); getApp()->emotes->twitch.getOrCreateEmote(id, code);

View file

@ -12,9 +12,9 @@ TwitchEmotes::TwitchEmotes()
{ {
} }
QString TwitchEmotes::cleanUpEmoteCode(const EmoteName &dirtyEmoteCode) QString TwitchEmotes::cleanUpEmoteCode(const QString &dirtyEmoteCode)
{ {
auto cleanCode = dirtyEmoteCode.string; auto cleanCode = dirtyEmoteCode;
cleanCode.detach(); cleanCode.detach();
static QMap<QString, QString> emoteNameReplacements{ static QMap<QString, QString> emoteNameReplacements{
@ -27,15 +27,12 @@ QString TwitchEmotes::cleanUpEmoteCode(const EmoteName &dirtyEmoteCode)
{"R-?\\)", "R)"}, {"B-?\\)", "B)"}, {"R-?\\)", "R)"}, {"B-?\\)", "B)"},
}; };
auto it = emoteNameReplacements.find(dirtyEmoteCode.string); auto it = emoteNameReplacements.find(dirtyEmoteCode);
if (it != emoteNameReplacements.end()) if (it != emoteNameReplacements.end())
{ {
cleanCode = it.value(); cleanCode = it.value();
} }
cleanCode.replace("&lt;", "<");
cleanCode.replace("&gt;", ">");
return cleanCode; return cleanCode;
} }
@ -44,29 +41,7 @@ QString TwitchEmotes::cleanUpEmoteCode(const EmoteName &dirtyEmoteCode)
EmotePtr TwitchEmotes::getOrCreateEmote(const EmoteId &id, EmotePtr TwitchEmotes::getOrCreateEmote(const EmoteId &id,
const EmoteName &name_) const EmoteName &name_)
{ {
static const QMap<QString, QString> replacements{ auto name = TwitchEmotes::cleanUpEmoteCode(name_.string);
{"[oO](_|\\.)[oO]", "O_o"}, {"\\&gt\\;\\(", "&gt;("},
{"\\&lt\\;3", "&lt;3"}, {"\\:-?(o|O)", ":O"},
{"\\:-?(p|P)", ":P"}, {"\\:-?[\\\\/]", ":/"},
{"\\:-?[z|Z|\\|]", ":Z"}, {"\\:-?\\(", ":("},
{"\\:-?\\)", ":)"}, {"\\:-?D", ":D"},
{"\\;-?(p|P)", ";P"}, {"\\;-?\\)", ";)"},
{"R-?\\)", "R)"}, {"B-?\\)", "B)"},
};
auto name = name_.string;
name.detach();
// replace < >
name.replace("<", "&lt;");
name.replace(">", "&gt;");
// replace regexes
auto it = replacements.find(name);
if (it != replacements.end())
{
name = it.value();
}
// search in cache or create new emote // search in cache or create new emote
auto cache = this->twitchEmotesCache_.access(); auto cache = this->twitchEmotesCache_.access();
@ -75,13 +50,13 @@ EmotePtr TwitchEmotes::getOrCreateEmote(const EmoteId &id,
if (!shared) if (!shared)
{ {
(*cache)[id] = shared = std::make_shared<Emote>(Emote{ (*cache)[id] = shared = std::make_shared<Emote>(Emote{
EmoteName{TwitchEmotes::cleanUpEmoteCode(EmoteName{name})}, EmoteName{name},
ImageSet{ ImageSet{
Image::fromUrl(getEmoteLink(id, "1.0"), 1), Image::fromUrl(getEmoteLink(id, "1.0"), 1),
Image::fromUrl(getEmoteLink(id, "2.0"), 0.5), Image::fromUrl(getEmoteLink(id, "2.0"), 0.5),
Image::fromUrl(getEmoteLink(id, "3.0"), 0.25), Image::fromUrl(getEmoteLink(id, "3.0"), 0.25),
}, },
Tooltip{name + "<br>Twitch Emote"}, Tooltip{name.toHtmlEscaped() + "<br>Twitch Emote"},
Url{QString("https://twitchemotes.com/emotes/%1").arg(id.string)}}); Url{QString("https://twitchemotes.com/emotes/%1").arg(id.string)}});
} }

View file

@ -36,7 +36,7 @@ struct CheerEmoteSet {
class TwitchEmotes class TwitchEmotes
{ {
public: public:
static QString cleanUpEmoteCode(const EmoteName &dirtyEmoteCode); static QString cleanUpEmoteCode(const QString &dirtyEmoteCode);
TwitchEmotes(); TwitchEmotes();
EmotePtr getOrCreateEmote(const EmoteId &id, const EmoteName &name); EmotePtr getOrCreateEmote(const EmoteId &id, const EmoteName &name);