summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2018-10-24 20:40:51 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2018-10-25 09:18:39 (GMT)
commit5ce9e19ef0744f530a797c30a82e9723eb7ea306 (patch)
treef3f59b3e9a7dddff75fd222d15b3492c26bb86be
parentf0b7ffcea9b9983555b0555ea5815a193d1e129c (diff)
downloadswift-5ce9e19ef0744f530a797c30a82e9723eb7ea306.zip
swift-5ce9e19ef0744f530a797c30a82e9723eb7ea306.tar.bz2
Strip off trailing dot from domainpart of jid
RFC 6122 specifies that if a domainpart ends in a dot, it must be stripped off before any other canonicalisation steps are taken. Unit tests have been added to check that various JID scenarios with a domain ending in a dot pass or are rejected as expected. Test-Information: Unit tests pass on macOS 10.13. Manual tests in sluift show expected behaviour. Change-Id: Id6813aaa4422a81bff0a4559eacd6855ef104dc3
-rw-r--r--Swiften/JID/JID.cpp7
-rw-r--r--Swiften/JID/UnitTest/JIDTest.cpp48
2 files changed, 53 insertions, 2 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp
index a31c19f..fff88e9 100644
--- a/Swiften/JID/JID.cpp
+++ b/Swiften/JID/JID.cpp
@@ -113,3 +113,8 @@ void JID::nameprepAndSetComponents(const std::string& node, const std::string& d
node_ = idnConverter->getStringPrepared(node, IDNConverter::XMPPNodePrep);
- domain_ = idnConverter->getStringPrepared(domain, IDNConverter::NamePrep);
+ if (domain.back() == '.') {
+ domain_ = idnConverter->getStringPrepared(domain.substr(0, domain.size() - 1), IDNConverter::NamePrep);
+ }
+ else {
+ domain_ = idnConverter->getStringPrepared(domain, IDNConverter::NamePrep);
+ }
resource_ = idnConverter->getStringPrepared(resource, IDNConverter::XMPPResourcePrep);
diff --git a/Swiften/JID/UnitTest/JIDTest.cpp b/Swiften/JID/UnitTest/JIDTest.cpp
index aefda33..0753fb5 100644
--- a/Swiften/JID/UnitTest/JIDTest.cpp
+++ b/Swiften/JID/UnitTest/JIDTest.cpp
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
@@ -22,3 +22,7 @@ class JIDTest : public CppUnit::TestFixture
CPPUNIT_TEST(testConstructorWithString_OnlyDomain);
+ CPPUNIT_TEST(testConstructorWithString_OnlyDomainWithDot);
+ CPPUNIT_TEST(testConstructorWithString_OnlyDomainDotStrippedOff);
+ CPPUNIT_TEST(testConstructorWithString_InvalidOnlyDomainSingleDot);
CPPUNIT_TEST(testConstructorWithString_InvalidDomain);
+ CPPUNIT_TEST(testConstructorWithString_InvalidDomainEmptyLabel);
CPPUNIT_TEST(testConstructorWithString_UpperCaseNode);
@@ -29,2 +33,4 @@ class JIDTest : public CppUnit::TestFixture
CPPUNIT_TEST(testConstructorWithString_EmptyDomainWithResource);
+ CPPUNIT_TEST(testConstructorWithString_DotDomain);
+ CPPUNIT_TEST(testConstructorWithString_DotDomainWithResource);
CPPUNIT_TEST(testConstructorWithString_IllegalResource);
@@ -124,2 +130,26 @@ class JIDTest : public CppUnit::TestFixture
+ void testConstructorWithString_OnlyDomainWithDot() {
+ JID testling("bar.");
+
+ CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getNode());
+ CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain());
+ CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getResource());
+ CPPUNIT_ASSERT(testling.isBare());
+ CPPUNIT_ASSERT(testling.isValid());
+ }
+
+ void testConstructorWithString_OnlyDomainDotStrippedOff() {
+ JID testling("foo.@bar./resource.");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("foo."), testling.getNode());
+ CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain());
+ CPPUNIT_ASSERT_EQUAL(std::string("resource."), testling.getResource());
+ CPPUNIT_ASSERT(!testling.isBare());
+ CPPUNIT_ASSERT(testling.isValid());
+ }
+
+ void testConstructorWithString_InvalidOnlyDomainSingleDot() {
+ CPPUNIT_ASSERT(!JID(".").isValid());
+ }
+
void testConstructorWithString_InvalidDomain() {
@@ -128,2 +158,6 @@ class JIDTest : public CppUnit::TestFixture
+ void testConstructorWithString_InvalidDomainEmptyLabel() {
+ CPPUNIT_ASSERT(!JID("foo@bar..").isValid());
+ }
+
void testConstructorWithString_UpperCaseNode() {
@@ -174,2 +208,14 @@ class JIDTest : public CppUnit::TestFixture
+ void testConstructorWithString_DotDomain() {
+ JID testling("bar@.");
+
+ CPPUNIT_ASSERT(!testling.isValid());
+ }
+
+ void testConstructorWithString_DotDomainWithResource() {
+ JID testling("bar@./resource");
+
+ CPPUNIT_ASSERT(!testling.isValid());
+ }
+
void testConstructorWithString_IllegalResource() {