summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2018-04-18 15:12:35 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2018-04-18 15:12:35 (GMT)
commit8fe63ff4b47cfa3b1e988f348b34ac7d36ce7b9b (patch)
treead8808aa5fda08174dc0f5f54540f621c471d513 /Swiften/JID/JID.cpp
parentfa2c9c62260ad793edf7082922d4ccda2a9564d8 (diff)
downloadswift-8fe63ff4b47cfa3b1e988f348b34ac7d36ce7b9b.zip
swift-8fe63ff4b47cfa3b1e988f348b34ac7d36ce7b9b.tar.bz2
Mark jids with an empty domainpart as invalid
When Swiften parsed jids with an empty domainpart (e.g. user@/resource), it would mark the jid as valid, and treat the localpart as domainpart. RFC 6122 states in 2.2 that "A domainpart MUST NOT be zero bytes in length". Unit tests for both a bare jid and a full jid with an empty domainpart have been added. Test-Information: Unit tests pass on Debian 9 Change-Id: Iadaf399cd4158666bfcdd6c075b8bf2102ff5538
Diffstat (limited to 'Swiften/JID/JID.cpp')
-rw-r--r--Swiften/JID/JID.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp
index c82674d..e8a4700 100644
--- a/Swiften/JID/JID.cpp
+++ b/Swiften/JID/JID.cpp
@@ -104,12 +104,12 @@ void JID::initializeFromString(const std::string& jid) {
hasResource_ = false;
bare = jid;
}
- std::pair<std::string,std::string> nodeAndDomain = String::getSplittedAtFirst(bare, '@');
- if (nodeAndDomain.second.empty()) {
- nameprepAndSetComponents("", nodeAndDomain.first, resource);
+ auto firstMatch = bare.find('@');
+ if (firstMatch != bare.npos) {
+ nameprepAndSetComponents(bare.substr(0, firstMatch), bare.substr(firstMatch + 1), resource);
}
else {
- nameprepAndSetComponents(nodeAndDomain.first, nodeAndDomain.second, resource);
+ nameprepAndSetComponents("", bare, resource);
}
}