From 945a5cd09cf055a3acd08db8aebce11e8f88fe29 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Wed, 3 Jun 2020 12:22:14 +0200 Subject: [PATCH] misc: Don't crash on URLs without port number Let misc:uri_parse/1 return default HTTP(S) port number if the URL doesn't specify a port number, analogous to the behavior when USE_OLD_HTTP_URI is defined. --- src/misc.erl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/misc.erl b/src/misc.erl index 2574c005a..85d11da4a 100644 --- a/src/misc.erl +++ b/src/misc.erl @@ -65,8 +65,14 @@ uri_parse(URL) -> uri_parse(URL) when is_binary(URL) -> uri_parse(binary_to_list(URL)); uri_parse(URL) -> - #{scheme:=Scheme,host:=Host,port:=Port,path:=Path} = uri_string:parse(URL), - {ok, Scheme, Host, Port, Path}. + case uri_string:parse(URL) of + #{scheme := Scheme, host := Host, port := Port, path := Path} -> + {ok, Scheme, Host, Port, Path}; + #{scheme := "https", host := Host, path := Path} -> + {ok, "https", Host, 443, Path}; + #{scheme := "http", host := Host, path := Path} -> + {ok, "http", Host, 80, Path} + end. -endif. -ifdef(USE_OLD_CRYPTO_HMAC).