From df07a5e1e654c5fe4b513b8b0e41a392e9955cdf Mon Sep 17 00:00:00 2001 From: Joanna Hulboj Date: Thu, 3 Oct 2019 09:11:09 +0100 Subject: 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 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 } const auto isAnyOfNonNumericAndNotDot = std::any_of(std::begin(domain), std::end(domain), [](char c) {return !::isdigit(c) && c != '.'; }); + const auto isDomainAllNumeric = std::all_of(std::begin(domain), std::end(domain), [](char c) {return ::isdigit(c) ; }); - if (!isAnyOfNonNumericAndNotDot) { + //Prevent Windows validating non-dotted integers as OK if it can unpack them + if (!isAnyOfNonNumericAndNotDot && !isDomainAllNumeric) { auto hostAddress = HostAddress::fromString(domain); if (hostAddress && hostAddress->isValid()) { 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 CPPUNIT_TEST(testConstructorWithString_OnlyDomainDotStrippedOff); CPPUNIT_TEST(testConstructorWithString_InvalidOnlyDomainSingleDot); CPPUNIT_TEST(testConstructorWithString_InvalidDomain); + CPPUNIT_TEST(testConstructorWithString_InvalidDomainOnlyDigits); CPPUNIT_TEST(testConstructorWithString_InvalidDomainEmptyLabel); CPPUNIT_TEST(testConstructorWithString_UpperCaseNode); CPPUNIT_TEST(testConstructorWithString_UpperCaseDomain); @@ -162,6 +163,10 @@ class JIDTest : public CppUnit::TestFixture CPPUNIT_ASSERT(!JID("foo@bar,baz").isValid()); } + void testConstructorWithString_InvalidDomainOnlyDigits() { + CPPUNIT_ASSERT(!JID("1234").isValid()); + } + void testConstructorWithString_InvalidDomainEmptyLabel() { CPPUNIT_ASSERT(!JID("foo@bar..").isValid()); } -- cgit v0.10.2-6-g49f6