sock_util: Allow URLs without path as valid
URLs without a path were treated as invalid, while according to the URL specification they are valid Also fixes a missing null terminator in the returned path
This commit is contained in:
parent
3402e3509c
commit
3096823ab4
@ -114,7 +114,7 @@ static char* _find_pathstart(const char *url)
|
|||||||
}
|
}
|
||||||
urlpos++;
|
urlpos++;
|
||||||
}
|
}
|
||||||
return NULL;
|
return urlpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sock_urlsplit(const char *url, char *hostport, char *urlpath)
|
int sock_urlsplit(const char *url, char *hostport, char *urlpath)
|
||||||
@ -125,9 +125,6 @@ int sock_urlsplit(const char *url, char *hostport, char *urlpath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *pathstart = _find_pathstart(hoststart);
|
char *pathstart = _find_pathstart(hoststart);
|
||||||
if(!pathstart) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(hostport, hoststart, pathstart - hoststart);
|
memcpy(hostport, hoststart, pathstart - hoststart);
|
||||||
|
|
||||||
@ -135,9 +132,7 @@ int sock_urlsplit(const char *url, char *hostport, char *urlpath)
|
|||||||
if (pathlen) {
|
if (pathlen) {
|
||||||
memcpy(urlpath, pathstart, pathlen);
|
memcpy(urlpath, pathstart, pathlen);
|
||||||
}
|
}
|
||||||
else {
|
*(urlpath + pathlen) = '\0';
|
||||||
*urlpath = '\0';
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user