mirror of
https://github.com/profanity-im/profanity.git
synced 2024-09-01 19:24:15 -04:00
Merge pull request #1632 from profanity-im/fix-split-url
Fix `_split_url()`
This commit is contained in:
commit
832f28bcb2
@ -929,14 +929,31 @@ _split_url(const char* alturi, gchar** host, gint* port)
|
||||
ptrdiff_t hostlen;
|
||||
/* search ':' from start and end
|
||||
* if `first` matches `last` it's a `hostname:port` combination
|
||||
* if `first` is different than `last` it's `[ip:v6]:port`
|
||||
* if `first` is different than `last` it's `[ip:v6]` or `[ip:v6]:port`
|
||||
*/
|
||||
char* first = strchr(alturi, ':');
|
||||
char* last = strrchr(alturi, ':');
|
||||
if (first && first == last) {
|
||||
if (first) {
|
||||
if (first == last) {
|
||||
hostlen = last - alturi;
|
||||
if (!strtoi_range(last + 1, port, 1, 65535, NULL))
|
||||
return FALSE;
|
||||
} else {
|
||||
/* IPv6 handling */
|
||||
char* bracket = strrchr(alturi, ']');
|
||||
if (!bracket)
|
||||
return FALSE;
|
||||
if (bracket > last) {
|
||||
/* `[ip:v6]` */
|
||||
hostlen = strlen(alturi) + 1;
|
||||
*port = 0;
|
||||
} else {
|
||||
/* `[ip:v6]:port` */
|
||||
hostlen = last - alturi;
|
||||
if (!strtoi_range(last + 1, port, 1, 65535, NULL))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
hostlen = strlen(alturi) + 1;
|
||||
*port = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user