Skip to content

IPv6 addresses with brackets are not handled correctly.  #34

@ahankinson

Description

@ahankinson

The gleam/uri package handles parsing URIs with brackets correctly, since it uses the regex from rfc3986. As a consequence, it does not handle URIs that do not have brackets.

import gleam/io
import gleam/uri

pub fn main() {
  uri.parse("http://[123:456::789]:8000/com")
  |> io.debug
  // Ok(Uri(scheme: Some("http"), userinfo: None, host: Some("[123:456::789]"), port: Some(8000), path: "/com", query: None, fragment: None))


  uri.parse("http://123:456::789:8000/com")
  |> io.debug
  // Ok(Uri(scheme: Some("http"), userinfo: None, host: Some("123"), port: Some(456), path: "/com", query: None, fragment: None))
}

(The latter case should probably fail instead of producing an invalid host value, but that's another issue).

However, the httpc package is not currently configured to accept IPv6 addresses with brackets. Passing an IPv6 URI from uri.parse will produce value => {error,invalid_uri}

I'm wondering if the underlying erlang httpc module needs to have "ipv6_host_with_brackets" set to True?

https://www.erlang.org/doc/apps/inets/httpc.html#request/4

Here are some public IPv6 URIs to try:

http://[2606:2800:21f:cb07:6820:80da:af6b:8b2c] -> example.net, should give a 404 Not Found
http://[2a00:1450:400a:808::200e] -> google.com, should also give a 404

These should both succeed with httpc, and not error out with "invalid URI".

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions