diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-12-24 18:21:41 +0100 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-12-24 22:29:44 +0100 |
commit | ecaf0093e5857074b51607924035555a4442d4d1 (patch) | |
tree | 7a1a5caa7f969f5d3f60e7e061098e867a3ea7e3 | |
parent | e617f0151df9a5edbefeb2c36d306a2989a278af (diff) | |
download | libquotient-ecaf0093e5857074b51607924035555a4442d4d1.tar.gz libquotient-ecaf0093e5857074b51607924035555a4442d4d1.zip |
Room: don't accept . at 0-th position in the tag
Also: use a structured binding for better code readability.
(cherry picked from commit 66972c81d018231f08f3767feda4b41ae5e1b8e0)
-rw-r--r-- | lib/room.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index 55e2931e..a19624d8 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1010,11 +1010,11 @@ TagRecord Room::tag(const QString& name) const { return d->tags.value(name); } std::pair<bool, QString> validatedTag(QString name) { - if (name.contains('.')) + if (name.isEmpty() || name.indexOf('.', 1) != -1) return { false, name }; qCWarning(MAIN) << "The tag" << name - << "doesn't follow the CS API conventions"; + << "doesn't follow the CS API conventions"; name.prepend("u."); qCWarning(MAIN) << "Using " << name << "instead"; @@ -1082,11 +1082,11 @@ void Room::Private::setTags(TagsMap&& newTags) emit q->tagsAboutToChange(); const auto keys = newTags.keys(); for (const auto& k : keys) - if (const auto& checkRes = validatedTag(k); checkRes.first) { - if (newTags.contains(checkRes.second)) + if (const auto& [adjusted, adjustedTag] = validatedTag(k); adjusted) { + if (newTags.contains(adjustedTag)) newTags.remove(k); else - newTags.insert(checkRes.second, newTags.take(k)); + newTags.insert(adjustedTag, newTags.take(k)); } tags = move(newTags); |