oatpp / oatpp

🌱Light and powerful C++ web framework for highly scalable and resource-efficient web application. It's zero-dependency and easy-portable.
https://oatpp.io/
Apache License 2.0
7.73k stars 1.3k forks source link

Wrong parsing of relative URLs #305

Open srogatch opened 3 years ago

srogatch commented 3 years ago

Consider the following relative URL and its parsing with oatpp:

std::string googleUrl="/url?q=https://apps.quanticfoundry.com/recommendations/gamerprofile/videogame/&sa=U&ved=2ahUKEwj_3NHchPfrAhVlk4sKHQNtCHIQFjAAegQIBBAB&usg=AOvVaw2BELlxCNpDwCHqFTwOx_EE";
oatpp::String sOatUrl(googleUrl.c_str(), googleUrl.size(), false);
oatpp::network::Url oatUrl = oatpp::network::Url::Parser::parseUrl(sOatUrl);

Unfortunately, /url?q=https:// gets into the scheme part, and so on the parsing gets wrong.

lganzzzo commented 3 years ago

Hey @srogatch ,

Thanks for the bug report!

As a workaround you may do directly parseQueryParams like this:

  oatpp::String urlStr = "/url?q=https://apps.quanticfoundry.com/recommendations/gamerprofile/videogame/&sa=U&ved=2ahUKEwj_3NHchPfrAhVlk4sKHQNtCHIQFjAAegQIBBAB&usg=AOvVaw2BELlxCNpDwCHqFTwOx_EE";
  auto params = oatpp::network::Url::Parser::parseQueryParams(urlStr);

  for(auto& p : params.getAll()) {
    //oatpp::String name = p.first.toString(); // Do like this if you need
    //oatpp::String value = p.second.toString();
    OATPP_LOGD("AAA", "name='%s', value='%s'", p.first.getData(), p.second.getData());
  }

Output:

 D |2020-09-21 00:48:38 1600638518956974| AAA:name='usg', value='AOvVaw2BELlxCNpDwCHqFTwOx_EE'
 D |2020-09-21 00:48:38 1600638518957457| AAA:name='ved', value='2ahUKEwj_3NHchPfrAhVlk4sKHQNtCHIQFjAAegQIBBAB'
 D |2020-09-21 00:48:38 1600638518957468| AAA:name='sa', value='U'
 D |2020-09-21 00:48:38 1600638518957476| AAA:name='q', value='https://apps.quanticfoundry.com/recommendations/gamerprofile/videogame/'
srogatch commented 3 years ago

Thanks, @lganzzzo , that works.