aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Uri.cpp12
-rw-r--r--test/src/UriTests.cpp3
2 files changed, 10 insertions, 5 deletions
diff --git a/src/Uri.cpp b/src/Uri.cpp
index ba04298..38dbe50 100644
--- a/src/Uri.cpp
+++ b/src/Uri.cpp
@@ -466,11 +466,15 @@ namespace Uri {
bool Uri::ParseFromString(const std::string& uriString) {
// First parse the scheme.
- auto authorityDelimiter = uriString.find("//");
- if (authorityDelimiter == std::string::npos) {
- authorityDelimiter = uriString.length();
+ // Limit our search so we don't scan into the authority
+ // or path elements, because these may have the colon
+ // character as well, which we might misinterpret
+ // as the scheme delimiter.
+ auto authorityOrPathDelimiterStart = uriString.find('/');
+ if (authorityOrPathDelimiterStart == std::string::npos) {
+ authorityOrPathDelimiterStart = uriString.length();
}
- const auto schemeEnd = uriString.substr(0, authorityDelimiter).find(':');
+ const auto schemeEnd = uriString.substr(0, authorityOrPathDelimiterStart).find(':');
std::string rest;
if (schemeEnd == std::string::npos) {
impl_->scheme.clear();
diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp
index d7ada25..4c1f307 100644
--- a/test/src/UriTests.cpp
+++ b/test/src/UriTests.cpp
@@ -349,13 +349,14 @@ TEST(UriTests, ParseFromStringHostBarelyLegal) {
}
}
-TEST(UriTests, ParseFromStringDontMisinterpretColonInAuthorityAsSchemeDelimiter) {
+TEST(UriTests, ParseFromStringDontMisinterpretColonInOtherPlacesAsSchemeDelimiter) {
const std::vector< std::string > testVectors{
{"//foo:bar@www.example.com/"},
{"//www.example.com/a:b"},
{"//www.example.com/foo?a:b"},
{"//www.example.com/foo#a:b"},
{"//[v7.:]/"},
+ {"/:/foo"},
};
size_t index = 0;
for (const auto& testVector : testVectors) {