aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Uri.cpp7
-rw-r--r--test/src/UriTests.cpp37
2 files changed, 43 insertions, 1 deletions
diff --git a/src/Uri.cpp b/src/Uri.cpp
index b30796c..08304d3 100644
--- a/src/Uri.cpp
+++ b/src/Uri.cpp
@@ -7,6 +7,7 @@
*/
#include "IsCharacterInSet.hpp"
+#include "NormalizeCaseInsensitiveString.hpp"
#include "PercentEncodedCharacterDecoder.hpp"
#include <functional>
@@ -467,6 +468,7 @@ namespace Uri {
int decodedCharacter = 0;
host.clear();
PercentEncodedCharacterDecoder pecDecoder;
+ bool hostIsRegName = false;
for (const auto c: hostPortString) {
switch(decoderState) {
case 0: { // first character
@@ -476,6 +478,7 @@ namespace Uri {
break;
} else {
decoderState = 1;
+ hostIsRegName = true;
}
}
@@ -555,6 +558,9 @@ namespace Uri {
} break;
}
}
+ if (hostIsRegName) {
+ host = NormalizeCaseInsensitiveString(host);
+ }
if (portString.empty()) {
hasPort = false;
} else {
@@ -600,6 +606,7 @@ namespace Uri {
) {
return false;
}
+ impl_->scheme = NormalizeCaseInsensitiveString(impl_->scheme);
rest = uriString.substr(schemeEnd + 1);
}
diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp
index bb541d0..4242885 100644
--- a/test/src/UriTests.cpp
+++ b/test/src/UriTests.cpp
@@ -275,6 +275,23 @@ TEST(UriTests, ParseFromStringSchemeBarelyLegal) {
}
}
+TEST(UriTests, ParseFromStringSchemeMixedCase) {
+ const std::vector< std::string > testVectors{
+ {"http://www.example.com/"},
+ {"hTtp://www.example.com/"},
+ {"HTTP://www.example.com/"},
+ {"Http://www.example.com/"},
+ {"HttP://www.example.com/"},
+ };
+ size_t index = 0;
+ for (const auto& testVector : testVectors) {
+ Uri::Uri uri;
+ ASSERT_TRUE(uri.ParseFromString(testVector)) << index;
+ ASSERT_EQ("http", uri.GetScheme()) << ">>> Failed for test vector element " << index << " <<<";
+ ++index;
+ }
+}
+
TEST(UriTests, ParseFromStringUserInfoIllegalCharacters) {
const std::vector< std::string > testVectors{
{"//%X@www.example.com/"},
@@ -331,7 +348,7 @@ TEST(UriTests, ParseFromStringHostBarelyLegal) {
std::string host;
};
const std::vector< TestVector > testVectors{
- {"//%41/", "A"},
+ {"//%41/", "a"},
{"///", ""},
{"//!/", "!"},
{"//'/", "'"},
@@ -339,6 +356,7 @@ TEST(UriTests, ParseFromStringHostBarelyLegal) {
{"//;/", ";"},
{"//1.2.3.4/", "1.2.3.4"},
{"//[v7.:]/", "[v7.:]"},
+ {"//[v7.aB]/", "[v7.aB]"},
};
size_t index = 0;
for (const auto& testVector : testVectors) {
@@ -349,6 +367,23 @@ TEST(UriTests, ParseFromStringHostBarelyLegal) {
}
}
+TEST(UriTests, ParseFromStringHostMixedCase) {
+ const std::vector< std::string > testVectors{
+ {"http://www.example.com/"},
+ {"http://www.EXAMPLE.com/"},
+ {"http://www.exAMple.com/"},
+ {"http://www.example.cOM/"},
+ {"http://wWw.exampLe.Com/"},
+ };
+ size_t index = 0;
+ for (const auto& testVector : testVectors) {
+ Uri::Uri uri;
+ ASSERT_TRUE(uri.ParseFromString(testVector)) << index;
+ ASSERT_EQ("www.example.com", uri.GetHost()) << ">>> Failed for test vector element " << index << " <<<";
+ ++index;
+ }
+}
+
TEST(UriTests, ParseFromStringDontMisinterpretColonInOtherPlacesAsSchemeDelimiter) {
const std::vector< std::string > testVectors{
{"//foo:bar@www.example.com/"},