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 18:21:41 +0100 |
commit | 66972c81d018231f08f3767feda4b41ae5e1b8e0 (patch) | |
tree | 6e0c22a0ea6df1278a5a0993ab87ca74c7d07f74 | |
parent | 0a2acd750a4155969092be674ed3dd9a71b2354f (diff) | |
download | libquotient-66972c81d018231f08f3767feda4b41ae5e1b8e0.tar.gz libquotient-66972c81d018231f08f3767feda4b41ae5e1b8e0.zip |
Room: don't accept . at 0-th position in the tag
Also: use a structured binding for better code readability.
-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 fcc22436..9c932ed6 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1026,11 +1026,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"; @@ -1098,11 +1098,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); |