From 4bda28b7185d75c11e9045cb68fdb3ba181082d4 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Thu, 30 May 2024 16:38:15 +0200 Subject: [PATCH] net.urllib: update parse host to allow for better error handling (#21602) --- vlib/net/urllib/urllib.v | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/vlib/net/urllib/urllib.v b/vlib/net/urllib/urllib.v index 41b5fd99f2a06a..3743181339f99c 100644 --- a/vlib/net/urllib/urllib.v +++ b/vlib/net/urllib/urllib.v @@ -564,7 +564,7 @@ fn parse_host(host string) !string { if host.len > 0 && host[0] == `[` { // parse an IP-Literal in RFC 3986 and RFC 6874. // E.g., '[fe80::1]', '[fe80::1%25en0]', '[fe80::1]:80'. - mut i := host.index_u8_last(`]`) + i := host.index_u8_last(`]`) if i == -1 { return error(error_msg("parse_host: missing ']' in host", '')) } @@ -580,9 +580,9 @@ fn parse_host(host string) !string { // We do impose some restrictions on the zone, to avoid stupidity // like newlines. if zone := host[..i].index('%25') { - host1 := unescape(host[..zone], .encode_host) or { return err.msg() } - host2 := unescape(host[zone..i], .encode_zone) or { return err.msg() } - host3 := unescape(host[i..], .encode_host) or { return err.msg() } + host1 := unescape(host[..zone], .encode_host)! + host2 := unescape(host[zone..i], .encode_zone)! + host3 := unescape(host[i..], .encode_host)! return host1 + host2 + host3 } } else { @@ -595,10 +595,8 @@ fn parse_host(host string) !string { } } } - h := unescape(host, .encode_host) or { return err.msg() } + h := unescape(host, .encode_host)! return h - // host = h - // return host } // set_path sets the path and raw_path fields of the URL based on the provided