Skip to content
Snippets Groups Projects
Commit 8dbbb86e authored by Nubben's avatar Nubben
Browse files

Fix bug in getHostFromURL

parent d992e7e2
No related branches found
No related tags found
No related merge requests found
......@@ -42,16 +42,14 @@ const std::string getDocumentFromURL(const std::string &url) {
* @return '' or a string with the found host
*/
const std::string getHostFromURL(const std::string &url) {
int slashes = 0;
unsigned int start = 0;
for (unsigned int i = 0; i < url.length(); i++) {
if (url[i] == '/') {
if (slashes == 2) {
return url.substr(start, i - start);
}
slashes++;
start = i + 1;
auto colonDoubleSlash = url.find("://");
if (colonDoubleSlash != std::string::npos) {
auto startPos = colonDoubleSlash + 3;
auto thirdSlash = url.find("/", startPos);
if (thirdSlash == std::string::npos) {
return url.substr(startPos);
}
return url.substr(startPos, thirdSlash - startPos);
}
return "";
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment