aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/src/UriTests.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp
index d5ab920..6d59697 100644
--- a/test/src/UriTests.cpp
+++ b/test/src/UriTests.cpp
@@ -418,3 +418,109 @@ TEST(UriTests, ParseFromStringPathBarelyLegal) {
++index;
}
}
+
+TEST(UriTests, ParseFromStringQueryIllegalCharacters) {
+ const std::vector< std::string > testVectors{
+ {"http://www.example.com/?foo[bar"},
+ {"http://www.example.com/?]bar"},
+ {"http://www.example.com/?foo]"},
+ {"http://www.example.com/?["},
+ {"http://www.example.com/?abc/foo]"},
+ {"http://www.example.com/?abc/["},
+ {"http://www.example.com/?foo]/abc"},
+ {"http://www.example.com/?[/abc"},
+ {"http://www.example.com/?foo]/"},
+ {"http://www.example.com/?[/"},
+ {"?foo[bar"},
+ {"?]bar"},
+ {"?foo]"},
+ {"?["},
+ {"?abc/foo]"},
+ {"?abc/["},
+ {"?foo]/abc"},
+ {"?[/abc"},
+ {"?foo]/"},
+ {"?[/"},
+ };
+ size_t index = 0;
+ for (const auto& testVector : testVectors) {
+ Uri::Uri uri;
+ ASSERT_FALSE(uri.ParseFromString(testVector)) << index;
+ ++index;
+ }
+}
+
+TEST(UriTests, ParseFromStringQueryBarelyLegal) {
+ struct TestVector {
+ std::string uriString;
+ std::string query;
+ };
+ const std::vector< TestVector > testVectors{
+ {"/?:/foo", ":/foo"},
+ {"?bob@/foo", "bob@/foo"},
+ {"?hello!", "hello!"},
+ {"urn:?hello,%20w%6Frld", "hello, world"},
+ {"//example.com/foo?(bar)/", "(bar)/"},
+ {"http://www.example.com/?foo?bar", "foo?bar" },
+ };
+ size_t index = 0;
+ for (const auto& testVector : testVectors) {
+ Uri::Uri uri;
+ ASSERT_TRUE(uri.ParseFromString(testVector.uriString)) << index;
+ ASSERT_EQ(testVector.query, uri.GetQuery());
+ ++index;
+ }
+}
+
+TEST(UriTests, ParseFromStringFragmentIllegalCharacters) {
+ const std::vector< std::string > testVectors{
+ {"http://www.example.com/#foo[bar"},
+ {"http://www.example.com/#]bar"},
+ {"http://www.example.com/#foo]"},
+ {"http://www.example.com/#["},
+ {"http://www.example.com/#abc/foo]"},
+ {"http://www.example.com/#abc/["},
+ {"http://www.example.com/#foo]/abc"},
+ {"http://www.example.com/#[/abc"},
+ {"http://www.example.com/#foo]/"},
+ {"http://www.example.com/#[/"},
+ {"#foo[bar"},
+ {"#]bar"},
+ {"#foo]"},
+ {"#["},
+ {"#abc/foo]"},
+ {"#abc/["},
+ {"#foo]/abc"},
+ {"#[/abc"},
+ {"#foo]/"},
+ {"#[/"},
+ };
+ size_t index = 0;
+ for (const auto& testVector : testVectors) {
+ Uri::Uri uri;
+ ASSERT_FALSE(uri.ParseFromString(testVector)) << index;
+ ++index;
+ }
+}
+
+TEST(UriTests, ParseFromStringFragmentBarelyLegal) {
+ struct TestVector {
+ std::string uriString;
+ std::string fragment;
+ };
+ const std::vector< TestVector > testVectors{
+ {"/#:/foo", ":/foo"},
+ {"#bob@/foo", "bob@/foo"},
+ {"#hello!", "hello!"},
+ {"urn:#hello,%20w%6Frld", "hello, world"},
+ {"//example.com/foo#(bar)/", "(bar)/"},
+ {"http://www.example.com/#foo?bar", "foo?bar" },
+ };
+ size_t index = 0;
+ for (const auto& testVector : testVectors) {
+ Uri::Uri uri;
+ ASSERT_TRUE(uri.ParseFromString(testVector.uriString)) << index;
+ ASSERT_EQ(testVector.fragment, uri.GetFragment());
+ ++index;
+ }
+}