From 6159c580884583bad0e17d4e96ea9ffc7e0be29a Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Wed, 11 Mar 2015 14:54:53 +0000 Subject: Don't allow JIDs with explicitly empty resources A JID may have no resource, but may not have an empty resource. Mark such JIDs as invalid. Test-Information: Added a unit test for the failure case (and made it pass). Other unit tests still pass Change-Id: I4fb300f716e635a3f8f02843891f25218da77130 diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp index a0f18d5..37fb755 100644 --- a/Swiften/JID/JID.cpp +++ b/Swiften/JID/JID.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -146,6 +146,9 @@ JID::JID(const std::string& node, const std::string& domain) : valid_(true), has } JID::JID(const std::string& node, const std::string& domain, const std::string& resource) : valid_(true), hasResource_(true) { + if (resource.empty()) { + valid_ = false; + } nameprepAndSetComponents(node, domain, resource); } diff --git a/Swiften/JID/JID.h b/Swiften/JID/JID.h index 00ee27f..0fd2f00 100644 --- a/Swiften/JID/JID.h +++ b/Swiften/JID/JID.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -195,4 +195,3 @@ namespace Swift { SWIFTEN_API std::ostream& operator<<(std::ostream& os, const Swift::JID& j); } - diff --git a/Swiften/JID/UnitTest/JIDTest.cpp b/Swiften/JID/UnitTest/JIDTest.cpp index 307243a..8f43576 100644 --- a/Swiften/JID/UnitTest/JIDTest.cpp +++ b/Swiften/JID/UnitTest/JIDTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -28,6 +28,7 @@ class JIDTest : public CppUnit::TestFixture CPPUNIT_TEST(testConstructorWithString_SpacesInNode); CPPUNIT_TEST(testConstructorWithStrings); CPPUNIT_TEST(testConstructorWithStrings_EmptyDomain); + CPPUNIT_TEST(testConstructorWithStrings_EmptyResource); CPPUNIT_TEST(testIsBare); CPPUNIT_TEST(testIsBare_NotBare); CPPUNIT_TEST(testToBare); @@ -154,7 +155,7 @@ class JIDTest : public CppUnit::TestFixture CPPUNIT_ASSERT(!JID(" alice@wonderland.lit").isValid()); CPPUNIT_ASSERT(!JID("alice @wonderland.lit").isValid()); } - + void testConstructorWithStrings() { JID testling("foo", "bar", "baz"); @@ -170,6 +171,12 @@ class JIDTest : public CppUnit::TestFixture CPPUNIT_ASSERT(!testling.isValid()); } + void testConstructorWithStrings_EmptyResource() { + JID testling("foo", "bar", ""); + + CPPUNIT_ASSERT(!testling.isValid()); + } + void testIsBare() { CPPUNIT_ASSERT(JID("foo@bar").isBare()); } -- cgit v0.10.2-6-g49f6