summary refs log tree commit diff
path: root/src/Cache.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-11-14 17:37:19 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-11-14 17:37:19 +0100
commitd26fe37010ec6ed1d83423607bfcae14335d0dbd (patch)
treee68673091c734af87b5782c52e0df59bfb85d925 /src/Cache.cpp
parentPrevent edits from removing quotes at the beginning of a message (diff)
downloadnheko-d26fe37010ec6ed1d83423607bfcae14335d0dbd.tar.xz
Disallow displaynames with only spaces or control characters
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r--src/Cache.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index 0fdf8dd3..c22cd0d6 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -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;