Fixed bug in 'url_to_hostname' function
This commit is contained in:
@@ -20,7 +20,8 @@ char* url_to_proto(char* url) {
|
||||
char* url_to_hostname(char* url) {
|
||||
/* This function relies on a hack-y assumption: that, given a string
|
||||
that represents a URL (e.g. https://www.example.com/index.html), the length of the host portion
|
||||
of the address is the distance between the second slash (:/'/') and the third ('/'index.html). */
|
||||
of the address is the distance between the second slash (:/'/') and the third ('/'index.html),
|
||||
or the second slash and the end of the string, if the path isn't present. */
|
||||
|
||||
size_t length = strlen(url);
|
||||
char* protocol = url_to_proto(url);
|
||||
@@ -41,6 +42,11 @@ char* url_to_hostname(char* url) {
|
||||
sentinel = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (sentinel == 0) { /* If there are no more slashes */
|
||||
return temp_substring;
|
||||
}
|
||||
strncpy(to_return,temp_substring,sentinel);
|
||||
free(temp_substring);
|
||||
return to_return;
|
||||
|
Reference in New Issue
Block a user