net.urllib: workaround an autofree bug for `if cond && opt() {`

pull/8068/head
Delyan Angelov 2021-01-12 16:28:59 +02:00
parent 4ffe3d83b8
commit ef18fb837c
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 5 additions and 3 deletions

View File

@ -997,9 +997,11 @@ fn split_host_port(hostport string) (string, string) {
mut host := hostport
mut port := ''
colon := host.last_index_byte(`:`)
if colon != -1 && valid_optional_port(host[colon..]) {
port = host[colon + 1..]
host = host[..colon]
if colon != -1 {
if valid_optional_port(host[colon..]) {
port = host[colon + 1..]
host = host[..colon]
}
}
if host.starts_with('[') && host.ends_with(']') {
host = host[1..host.len - 1]