hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 6b5547375f16bd66b522ee53762b3e61a5393bd3
parent 8eb27c2bda1efd3a39ceb1a78a4646f0c7afed8d
Author: Alexey Yerin <yyp@disroot.org>
Date:   Wed, 22 Feb 2023 15:36:07 +0300

net::uri: do not ignore invalid characters in parse_authority

Invalid URIs such as 'https://^a.b' were silently parsed as
'https://a.b'

Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Mnet/uri/+test.ha | 3+++
Mnet/uri/parse.ha | 12++++++------
2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/net/uri/+test.ha b/net/uri/+test.ha @@ -96,6 +96,9 @@ use net::ip; assert(parse(":") is invalid); assert(parse("hello*:") is invalid); assert(parse("hello") is invalid); + + // Unexpected character + assert(parse("https://^harelang.org") is invalid); }; @test fn percent_encoding() void = { diff --git a/net/uri/parse.ha b/net/uri/parse.ha @@ -163,23 +163,23 @@ fn parse_authority(in: *strings::iterator) ((str, u16, str) | invalid) = { if (len(userinfo) > 0 && is_userinfo(r)) { return invalid; }; - - if (r == '@') { + switch (r) { + case '@' => // This was userinfo+host[+port] userinfo = percent_decode(strio::string(&buf))?; strio::reset(&buf); - }; - if (r == '/') { + case '/' => // This was just host strings::prev(in); host = percent_decode(strio::string(&buf))?; break; - }; - if (r == ':') { + case ':' => // This was host+port host = percent_decode(strio::string(&buf))?; port = parse_port(in)?; break; + case => + return invalid; }; } else { strio::appendrune(&buf, r)!;