aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Uri.cpp4
-rw-r--r--test/src/UriTests.cpp34
2 files changed, 36 insertions, 2 deletions
diff --git a/src/Uri.cpp b/src/Uri.cpp
index 35631cf..309ce88 100644
--- a/src/Uri.cpp
+++ b/src/Uri.cpp
@@ -759,7 +759,9 @@ namespace Uri {
&& (oldPath[1] == "..")
) {
oldPath.erase(oldPath.begin() + 1);
- impl_->path.pop_back();
+ if (!impl_->path.empty()) {
+ impl_->path.pop_back();
+ }
} else
// Step 2D
diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp
index 4275de6..943c25c 100644
--- a/test/src/UriTests.cpp
+++ b/test/src/UriTests.cpp
@@ -593,13 +593,45 @@ TEST(UriTests, NormalizePath) {
const std::vector< TestVector > testVectors{
{"/a/b/c/./../../g", {"", "a", "g"}},
{"mid/content=5/../6", {"mid", "6"}},
+ {"http://example.com/a/../b", {"", "b"}},
+ {"http://example.com/../b", {"", "b"}},
+ {"http://example.com/a/../b", {"", "b"}},
+ {"http://example.com/a/../../b", {"", "b"}},
+ {"./a/b", {"a", "b"}},
+ {"..", {}},
+ {"/", {""}},
+ {"a/b/..", {"a"}},
+ {"a/b/.", {"a", "b"}},
+ {"a/b/./c", {"a", "b", "c"}},
+ {"a/b/./c/", {"a", "b", "c", ""}},
+ {"/a/b/..", {"", "a"}},
+ {"/a/b/.", {"", "a", "b"}},
+ {"/a/b/./c", {"", "a", "b", "c"}},
+ {"/a/b/./c/", {"", "a", "b", "c", ""}},
+ {"./a/b/..", {"a"}},
+ {"./a/b/.", {"a", "b"}},
+ {"./a/b/./c", {"a", "b", "c"}},
+ {"./a/b/./c/", {"a", "b", "c", ""}},
+ {"../a/b/..", {"a"}},
+ {"../a/b/.", {"a", "b"}},
+ {"../a/b/./c", {"a", "b", "c"}},
+ {"../a/b/./c/", {"a", "b", "c", ""}},
+ {"../a/b/../c", {"a", "c"}},
+ {"../a/b/./../c/", {"a", "c", ""}},
+ {"../a/b/./../c", {"a", "c"}},
+ {"../a/b/./../c/", {"a", "c", ""}},
+ {"../a/b/.././c/", {"a", "c", ""}},
+ {"../a/b/.././c", {"a", "c"}},
+ {"../a/b/.././c/", {"a", "c", ""}},
+ {"/./c/d", {"", "c", "d"}},
+ {"/../c/d", {"", "c", "d"}},
};
size_t index = 0;
for (const auto& testVector : testVectors) {
Uri::Uri uri;
ASSERT_TRUE(uri.ParseFromString(testVector.uriString)) << index;
uri.NormalizePath();
- ASSERT_EQ(testVector.normalizedPathSegments, uri.GetPath());
+ ASSERT_EQ(testVector.normalizedPathSegments, uri.GetPath()) << index;
++index;
}
}