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
- Bugfix: Fixed "smiley" emotes being unable to be "Tabbed" with autocompletion, introduced in v2.3.3. (#3010)
## 2.3.3
- 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)
{
str += emoteElement->getEmote()->getCopyString();
str = TwitchEmotes::cleanUpEmoteCode(EmoteName{str});
str = TwitchEmotes::cleanUpEmoteCode(str);
if (this->hasTrailingSpace())
{
str += " ";

View file

@ -240,12 +240,10 @@ void TwitchAccount::loadEmotes()
KrakenEmote krakenEmote(emoteArrObj.toObject());
auto id = EmoteId{krakenEmote.id};
auto code = EmoteName{krakenEmote.code};
auto code = EmoteName{
TwitchEmotes::cleanUpEmoteCode(krakenEmote.code)};
auto cleanCode =
EmoteName{TwitchEmotes::cleanUpEmoteCode(code)};
emoteSet->emotes.emplace_back(
TwitchEmote{id, cleanCode});
emoteSet->emotes.emplace_back(TwitchEmote{id, code});
if (!emoteSet->local)
{
@ -370,11 +368,11 @@ void TwitchAccount::loadUserstateEmotes()
IvrEmote ivrEmote(emoteObj.toObject());
auto id = EmoteId{ivrEmote.id};
auto code = EmoteName{ivrEmote.code};
auto cleanCode =
EmoteName{TwitchEmotes::cleanUpEmoteCode(code)};
auto code = EmoteName{
TwitchEmotes::cleanUpEmoteCode(ivrEmote.code)};
newUserEmoteSet->emotes.push_back(
TwitchEmote{id, cleanCode});
TwitchEmote{id, code});
auto emote =
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();
static QMap<QString, QString> emoteNameReplacements{
@ -27,15 +27,12 @@ QString TwitchEmotes::cleanUpEmoteCode(const EmoteName &dirtyEmoteCode)
{"R-?\\)", "R)"}, {"B-?\\)", "B)"},
};
auto it = emoteNameReplacements.find(dirtyEmoteCode.string);
auto it = emoteNameReplacements.find(dirtyEmoteCode);
if (it != emoteNameReplacements.end())
{
cleanCode = it.value();
}
cleanCode.replace("&lt;", "<");
cleanCode.replace("&gt;", ">");
return cleanCode;
}
@ -44,29 +41,7 @@ QString TwitchEmotes::cleanUpEmoteCode(const EmoteName &dirtyEmoteCode)
EmotePtr TwitchEmotes::getOrCreateEmote(const EmoteId &id,
const EmoteName &name_)
{
static const QMap<QString, QString> replacements{
{"[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();
}
auto name = TwitchEmotes::cleanUpEmoteCode(name_.string);
// search in cache or create new emote
auto cache = this->twitchEmotesCache_.access();
@ -75,13 +50,13 @@ EmotePtr TwitchEmotes::getOrCreateEmote(const EmoteId &id,
if (!shared)
{
(*cache)[id] = shared = std::make_shared<Emote>(Emote{
EmoteName{TwitchEmotes::cleanUpEmoteCode(EmoteName{name})},
EmoteName{name},
ImageSet{
Image::fromUrl(getEmoteLink(id, "1.0"), 1),
Image::fromUrl(getEmoteLink(id, "2.0"), 0.5),
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)}});
}

View file

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