diff options
author | Richard Walters <rwalters@digitalstirling.com> | 2018-07-01 15:20:30 -0700 |
---|---|---|
committer | Richard Walters <rwalters@digitalstirling.com> | 2018-07-01 15:20:30 -0700 |
commit | d3a446cd9c3846735f4ea9e5270352633c597071 (patch) | |
tree | 4dd760e75c295b340db489df35b5275e1fba9352 /test | |
parent | 4eb4f0c150642cf2fa92f75000ab5108d1908e48 (diff) |
Check for illegal characters in query and fragment elements
Diffstat (limited to 'test')
-rw-r--r-- | test/src/UriTests.cpp | 106 |
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; + } +} |