From a83d252c7e4aa6885319d64bbdb6aa54e1fb8f95 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Fri, 5 Oct 2012 18:33:13 +0200
Subject: Strip leading '/' from BOSH paths.

Resolves: #1167

diff --git a/Swiften/Base/URL.cpp b/Swiften/Base/URL.cpp
index 866cd45..320e2ad 100644
--- a/Swiften/Base/URL.cpp
+++ b/Swiften/Base/URL.cpp
@@ -45,7 +45,7 @@ URL URL::fromString(const std::string& urlString) {
 		}
 		else {
 			authority = urlString.substr(authorityIndex, slashIndex - authorityIndex);
-			path = unescape(urlString.substr(slashIndex));
+			path = unescape(urlString.substr(slashIndex + 1));
 		}
 
 		size_t atIndex = authority.find('@');
diff --git a/Swiften/Base/UnitTest/URLTest.cpp b/Swiften/Base/UnitTest/URLTest.cpp
index 55c81f6..09912ed 100644
--- a/Swiften/Base/UnitTest/URLTest.cpp
+++ b/Swiften/Base/UnitTest/URLTest.cpp
@@ -16,6 +16,7 @@ class URLTest : public CppUnit::TestFixture {
 		CPPUNIT_TEST_SUITE(URLTest);
 		CPPUNIT_TEST(testFromString);
 		CPPUNIT_TEST(testFromString_WithoutPath);
+		CPPUNIT_TEST(testFromString_WithRootPath);
 		CPPUNIT_TEST(testFromString_WithPort);
 		CPPUNIT_TEST(testFromString_WithPortWithoutPath);
 		CPPUNIT_TEST(testFromString_WithUserInfo);
@@ -32,7 +33,7 @@ class URLTest : public CppUnit::TestFixture {
 			CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
 			CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
 			CPPUNIT_ASSERT(!url.getPort());
-			CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
+			CPPUNIT_ASSERT_EQUAL(std::string("baz/bam"), url.getPath());
 		}
 
 		void testFromString_WithoutPath() {
@@ -44,13 +45,22 @@ class URLTest : public CppUnit::TestFixture {
 			CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
 		}
 
+		void testFromString_WithRootPath() {
+			URL url = URL::fromString("http://foo.bar/");
+			
+			CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+			CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
+			CPPUNIT_ASSERT(!url.getPort());
+			CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
+		}
+
 		void testFromString_WithPort() {
 			URL url = URL::fromString("http://foo.bar:1234/baz/bam");
 			
 			CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
 			CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
 			CPPUNIT_ASSERT_EQUAL(1234, *url.getPort());
-			CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
+			CPPUNIT_ASSERT_EQUAL(std::string("baz/bam"), url.getPath());
 		}
 
 		void testFromString_WithPortWithoutPath() {
@@ -67,7 +77,7 @@ class URLTest : public CppUnit::TestFixture {
 			
 			CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
 			CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
-			CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
+			CPPUNIT_ASSERT_EQUAL(std::string("baz/bam"), url.getPath());
 		}
 
 		void testFromString_NonASCIIHost() {
@@ -79,7 +89,7 @@ class URLTest : public CppUnit::TestFixture {
 		void testFromString_NonASCIIPath() {
 			URL url = URL::fromString("http://foo.bar/baz/tron%C3%A7on/bam");
 			
-			CPPUNIT_ASSERT_EQUAL(std::string("/baz/tron\xc3\xa7on/bam"), url.getPath());
+			CPPUNIT_ASSERT_EQUAL(std::string("baz/tron\xc3\xa7on/bam"), url.getPath());
 		}
 
 		void testToString() {
-- 
cgit v0.10.2-6-g49f6