hackney
hackney copied to clipboard
hackney_url:parse_url/1 raises an exception on a technically valid edge case
It looks like hackney is just splitting on @
and winds up trying to treat part of the credentials as the port when a url containing @
in the credentials is parsed.
iex(3)> :hackney_url.parse_url("https://[email protected]:p@[email protected]/some/path")
** (ArgumentError) argument error
:erlang.list_to_integer('p@[email protected]')
(hackney 1.16.0) /Users/adamkittelson/Code/paperboy/deps/hackney/src/hackney_url.erl:260: :hackney_url.parse_netloc/2
While this is admittedly a weird thing to do it is technically valid and parses correctly in other libraries. Elixir's URI module for example is able to parse it:
URI.parse("https://[email protected]:p@[email protected]/some/path")
%URI{
authority: "[email protected]:p@[email protected]",
fragment: nil,
host: "domain.com",
path: "/some/path",
port: 443,
query: nil,
scheme: "https",
userinfo: "[email protected]:p@assword"
}
For now I'm able to work around by parsing with URI and using the result to create the hackney_url record myself and passing that to hackney:request/5 but it would be great if hackney_url:parse_url/1 could be updated to follow the RFC.
The Elixir implementation for URI.parse/1 is here if that is useful: https://github.com/elixir-lang/elixir/blob/v1.10.0/lib/elixir/lib/uri.ex#L455
Thanks! Adam