mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
Disallow displaynames with only spaces or control characters
This commit is contained in:
parent
38e3498978
commit
d26fe37010
1 changed files with 12 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue