From 6c79c19334b53560ea9d2036da279994b8f83be4 Mon Sep 17 00:00:00 2001 From: Richard Walters Date: Sun, 1 Jul 2018 00:18:30 -0700 Subject: Handle bad characters in UserInfo --- test/src/UriTests.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/src') diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp index b4be2d5..d246a4d 100644 --- a/test/src/UriTests.cpp +++ b/test/src/UriTests.cpp @@ -274,3 +274,39 @@ TEST(UriTests, ParseFromStringSchemeBarelyLegal) { ++index; } } + +TEST(UriTests, ParseFromStringUserInfoIllegalCharacters) { + const std::vector< std::string > testVectors{ + {"//%X@www.example.com/"}, + {"//{@www.example.com/"}, + }; + size_t index = 0; + for (const auto& testVector : testVectors) { + Uri::Uri uri; + ASSERT_FALSE(uri.ParseFromString(testVector)) << index; + ++index; + } +} + +TEST(UriTests, ParseFromStringUserInfoBarelyLegal) { + struct TestVector { + std::string uriString; + std::string userInfo; + }; + const std::vector< TestVector > testVectors{ + {"//%41@www.example.com/", "A"}, + {"//@www.example.com/", ""}, + {"//!@www.example.com/", "!"}, + {"//'@www.example.com/", "'"}, + {"//(@www.example.com/", "("}, + {"//;@www.example.com/", ";"}, + {"http://:@www.example.com/", ":"}, + }; + size_t index = 0; + for (const auto& testVector : testVectors) { + Uri::Uri uri; + ASSERT_TRUE(uri.ParseFromString(testVector.uriString)) << index; + ASSERT_EQ(testVector.userInfo, uri.GetUserInfo()); + ++index; + } +} -- cgit v1.2.3