diff options
-rw-r--r-- | src/Uri.cpp | 9 | ||||
-rw-r--r-- | test/src/UriTests.cpp | 10 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/Uri.cpp b/src/Uri.cpp index 309ce88..2d549c2 100644 --- a/src/Uri.cpp +++ b/src/Uri.cpp @@ -671,6 +671,15 @@ namespace Uri { return false; } + // Handle special case of absolute URI with empty + // path -- treat the same as "/" path. + if ( + !impl_->scheme.empty() + && impl_->path.empty() + ) { + impl_->path.push_back(""); + } + // Next, parse the fragment if there is one. if (!impl_->ParseFragment(queryAndOrFragment, rest)) { return false; diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp index fcd6309..897047d 100644 --- a/test/src/UriTests.cpp +++ b/test/src/UriTests.cpp @@ -646,3 +646,13 @@ TEST(UriTests, ConstructNormalizeAndCompareEquivalentUris) { uri2.NormalizePath(); ASSERT_EQ(uri1, uri2); } + +TEST(UriTests, EmptyPathInUriWithAuthorityIsEquivalentToSlashOnlyPath) { + Uri::Uri uri1, uri2; + ASSERT_TRUE(uri1.ParseFromString("http://example.com")); + ASSERT_TRUE(uri2.ParseFromString("http://example.com/")); + ASSERT_EQ(uri1, uri2); + ASSERT_TRUE(uri1.ParseFromString("urn:")); + ASSERT_TRUE(uri2.ParseFromString("urn:/")); + ASSERT_EQ(uri1, uri2); +} |