aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2018-07-01 15:08:41 -0700
committerRichard Walters <rwalters@digitalstirling.com>2018-07-01 15:08:41 -0700
commit4eb4f0c150642cf2fa92f75000ab5108d1908e48 (patch)
treeacb4a6e2e39a0316a64c22b5ef3023716d995334 /test
parentb4cc26f831573d8dc122b4d2ba8a5f5d8d7e3773 (diff)
Check for illegal characters in path segments
Diffstat (limited to 'test')
-rw-r--r--test/src/UriTests.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp
index 4c1f307..d5ab920 100644
--- a/test/src/UriTests.cpp
+++ b/test/src/UriTests.cpp
@@ -366,3 +366,55 @@ TEST(UriTests, ParseFromStringDontMisinterpretColonInOtherPlacesAsSchemeDelimite
++index;
}
}
+
+TEST(UriTests, ParseFromStringPathIllegalCharacters) {
+ 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, ParseFromStringPathBarelyLegal) {
+ struct TestVector {
+ std::string uriString;
+ std::vector< std::string > path;
+ };
+ const std::vector< TestVector > testVectors{
+ {"/:/foo", {"", ":", "foo"}},
+ {"bob@/foo", {"bob@", "foo"}},
+ {"hello!", {"hello!"}},
+ {"urn:hello,%20w%6Frld", {"hello, world"}},
+ {"//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.path, uri.GetPath());
+ ++index;
+ }
+}