Merge pull request #852 from linhaojun857/url

Fix url parse bug
This commit is contained in:
Leonid Stryzhevskyi 2023-09-16 02:16:37 +03:00 committed by GitHub
commit d042b62bed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -149,9 +149,13 @@ Url Url::Parser::parseUrl(oatpp::parser::Caret& caret) {
Url result;
if(caret.findChar(':')) {
caret.setPosition(0);
result.scheme = parseScheme(caret);
caret.canContinueAtChar(':', 1);
if(caret.canContinueAtChar(':', 1) && !caret.isAtText("//", 2, true)) {
caret.setPosition(0);
} else {
caret.setPosition(0);
result.scheme = parseScheme(caret);
caret.canContinueAtChar(':', 1);
}
} else {
caret.setPosition(0);
}

View File

@ -118,6 +118,19 @@ void UrlTest::onRun() {
OATPP_ASSERT(url.queryParams.getSize() == 0)
}
{
const char* urlText = "oatpp.io:8000/path";
OATPP_LOGV(TAG, "urlText='%s'", urlText)
auto url = Url::Parser::parseUrl(urlText);
OATPP_ASSERT(url.scheme == nullptr)
OATPP_ASSERT(url.authority.userInfo == nullptr)
OATPP_ASSERT(url.authority.host && url.authority.host == "oatpp.io")
OATPP_ASSERT(url.authority.port == 8000)
OATPP_ASSERT(url.path == "/path")
OATPP_ASSERT(url.queryParams.getSize() == 0)
}
{
const char* urlText = "?key1=value1&key2=value2&key3=value3";
OATPP_LOGV(TAG, "urlText='%s'", urlText)