std.Uri & IPv6 address literals

I’ve been messing with RFC3986 URI’s in Zig, but noticed something odd with the standard library handles IPv6 address literals inside of a URI, such as the following: http://[::1]/
std.uri.Parse properly parses this string, and sets the host component to .{ .percent_encoded = "[::1]" }. This is the correct behavior according to RFC3986, which specifies that

A host identified by an Internet Protocol literal address, version 6 [RFC3513] or later, is distinguished by enclosing the IP literal within square brackets (“[” and “]”).

This also means that here the actual IPv6 address literal is ::1 and not [::1]. But the Zig standard library seems to try to parse [::1] as the IP address literal, which fails because an IPv6 address literal cannot contains square brackets.
As an example, the function std.http.Client.open indirectly sends the std.Uri’s host to std.net.tcpConnectToHost, which ends up failing with error.UnknownHostName.
If I manually remove the square brackets in code from the std.Uri before giving it to std.http.Client.open, then it works, but it is no longer a valid URI according to RFC3986.
Am I doing something wrong or is this a bug?

3 Likes