diff options
| author | Joanna Hulboj <joanna.hulboj@isode.com> | 2019-10-03 08:11:09 (GMT) |
|---|---|---|
| committer | Joanna Hulboj <joanna.hulboj@isode.com> | 2019-10-03 09:09:08 (GMT) |
| commit | df07a5e1e654c5fe4b513b8b0e41a392e9955cdf (patch) | |
| tree | e864e06a81c85bb1876c59a2f7107a443ed0cc75 | |
| parent | 6f5fa6a02eb7502a15afab70c91451b8142e2ac3 (diff) | |
| download | swift-df07a5e1e654c5fe4b513b8b0e41a392e9955cdf.zip swift-df07a5e1e654c5fe4b513b8b0e41a392e9955cdf.tar.bz2 | |
Treat numeric domain JID as invalid
DomainJID consisting of only numbers is not treated as valid.
Test-information:
Unit tests pass on Windows 10 and Ubuntu 18.04.1 LTS.
Change-Id: If23ba8b8ea2a3c72d6f6e3acec4f587166c14e61
| -rw-r--r-- | Swiften/JID/JID.cpp | 4 | ||||
| -rw-r--r-- | Swiften/JID/UnitTest/JIDTest.cpp | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp index 5c6ea9d..a584b79 100644 --- a/Swiften/JID/JID.cpp +++ b/Swiften/JID/JID.cpp | |||
| @@ -129,8 +129,10 @@ void JID::nameprepAndSetComponents(const std::string& node, const std::string& d | |||
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | const auto isAnyOfNonNumericAndNotDot = std::any_of(std::begin(domain), std::end(domain), [](char c) {return !::isdigit(c) && c != '.'; }); | 131 | const auto isAnyOfNonNumericAndNotDot = std::any_of(std::begin(domain), std::end(domain), [](char c) {return !::isdigit(c) && c != '.'; }); |
| 132 | const auto isDomainAllNumeric = std::all_of(std::begin(domain), std::end(domain), [](char c) {return ::isdigit(c) ; }); | ||
| 132 | 133 | ||
| 133 | if (!isAnyOfNonNumericAndNotDot) { | 134 | //Prevent Windows validating non-dotted integers as OK if it can unpack them |
| 135 | if (!isAnyOfNonNumericAndNotDot && !isDomainAllNumeric) { | ||
| 134 | auto hostAddress = HostAddress::fromString(domain); | 136 | auto hostAddress = HostAddress::fromString(domain); |
| 135 | if (hostAddress && hostAddress->isValid()) { | 137 | if (hostAddress && hostAddress->isValid()) { |
| 136 | setComponents(node, domain, resource); | 138 | setComponents(node, domain, resource); |
diff --git a/Swiften/JID/UnitTest/JIDTest.cpp b/Swiften/JID/UnitTest/JIDTest.cpp index 894378d..fc7583f 100644 --- a/Swiften/JID/UnitTest/JIDTest.cpp +++ b/Swiften/JID/UnitTest/JIDTest.cpp | |||
| @@ -24,6 +24,7 @@ class JIDTest : public CppUnit::TestFixture | |||
| 24 | CPPUNIT_TEST(testConstructorWithString_OnlyDomainDotStrippedOff); | 24 | CPPUNIT_TEST(testConstructorWithString_OnlyDomainDotStrippedOff); |
| 25 | CPPUNIT_TEST(testConstructorWithString_InvalidOnlyDomainSingleDot); | 25 | CPPUNIT_TEST(testConstructorWithString_InvalidOnlyDomainSingleDot); |
| 26 | CPPUNIT_TEST(testConstructorWithString_InvalidDomain); | 26 | CPPUNIT_TEST(testConstructorWithString_InvalidDomain); |
| 27 | CPPUNIT_TEST(testConstructorWithString_InvalidDomainOnlyDigits); | ||
| 27 | CPPUNIT_TEST(testConstructorWithString_InvalidDomainEmptyLabel); | 28 | CPPUNIT_TEST(testConstructorWithString_InvalidDomainEmptyLabel); |
| 28 | CPPUNIT_TEST(testConstructorWithString_UpperCaseNode); | 29 | CPPUNIT_TEST(testConstructorWithString_UpperCaseNode); |
| 29 | CPPUNIT_TEST(testConstructorWithString_UpperCaseDomain); | 30 | CPPUNIT_TEST(testConstructorWithString_UpperCaseDomain); |
| @@ -162,6 +163,10 @@ class JIDTest : public CppUnit::TestFixture | |||
| 162 | CPPUNIT_ASSERT(!JID("foo@bar,baz").isValid()); | 163 | CPPUNIT_ASSERT(!JID("foo@bar,baz").isValid()); |
| 163 | } | 164 | } |
| 164 | 165 | ||
| 166 | void testConstructorWithString_InvalidDomainOnlyDigits() { | ||
| 167 | CPPUNIT_ASSERT(!JID("1234").isValid()); | ||
| 168 | } | ||
| 169 | |||
| 165 | void testConstructorWithString_InvalidDomainEmptyLabel() { | 170 | void testConstructorWithString_InvalidDomainEmptyLabel() { |
| 166 | CPPUNIT_ASSERT(!JID("foo@bar..").isValid()); | 171 | CPPUNIT_ASSERT(!JID("foo@bar..").isValid()); |
| 167 | } | 172 | } |
Swift