Disallow displaynames with only spaces or control characters

This commit is contained in:
Nicolas Werner 2021-11-14 17:37:19 +01:00
parent 38e3498978
commit d26fe37010
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9

View file

@ -3828,17 +3828,24 @@ Cache::getMembersWithKeys(const std::string &room_id, bool verified_only)
QString
Cache::displayName(const QString &room_id, const QString &user_id)
{
if (auto info = getMember(room_id.toStdString(), user_id.toStdString());
info && !info->name.empty())
return QString::fromStdString(info->name);
return QString::fromStdString(displayName(room_id.toStdString(), user_id.toStdString()));
}
return user_id;
static bool
isDisplaynameSafe(const std::string &s)
{
for (QChar c : QString::fromStdString(s).toUcs4()) {
if (c.isPrint() && !c.isSpace())
return false;
}
return true;
}
std::string
Cache::displayName(const std::string &room_id, const std::string &user_id)
{
if (auto info = getMember(room_id, user_id); info && !info->name.empty())
if (auto info = getMember(room_id, user_id); info && !isDisplaynameSafe(info->name))
return info->name;
return user_id;