Skip to content

Commit

Permalink
Fix IPv6 address parsing (thanks to Michael Ayles)(#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
badlop committed Jun 6, 2022
1 parent f6231d9 commit 05a0569
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/esip_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,31 @@ decode_uri_host(Data, URI) ->
Params = decode_params(Ps)
end
end,
case split(HostPort, $:, 1) of
[Host, Port] ->
case to_integer(Port, 0, 65535) of
{ok, PortInt} ->
URI#uri{host = to_lower(Host), port = PortInt,
params = Params, hdrs = Headers};
_ ->
error
end;
[Host] ->
URI#uri{host = to_lower(Host), params = Params, hdrs = Headers}
case decode_uri_host2(split(HostPort, $:)) of
{Host, PortInt} ->
URI#uri{host = to_lower(Host), port = PortInt,
params = Params, hdrs = Headers};
_ ->
error
end.

decode_uri_host2([Host, Port]) ->
case to_integer(Port, 0, 65535) of
{ok, PortInt} ->
{Host, PortInt};
_ ->
error
end;
decode_uri_host2([_, _ | _] = Els) ->
case to_integer(lists:last(Els), 0, 65535) of
{ok, PortInt} ->
{list_to_binary(join(lists:droplast(Els), ":")), PortInt};
error ->
{list_to_binary(join(Els, ":")), undefined}
end;
decode_uri_host2([Host]) ->
{Host, undefined}.

encode_uri(#uri{scheme = Scheme,
user = User,
password = Password,
Expand Down

0 comments on commit 05a0569

Please sign in to comment.