From 7531bb0b9374dbb669d8e0e88a444593198066fe Mon Sep 17 00:00:00 2001 From: Antoine Denommee Pigeon Date: Wed, 16 Mar 2022 13:11:09 -0400 Subject: [PATCH] Correctly handle badly formatted protocols Remove the bad protocol from the URL instead of parsing that protocol inside the domain. Change-Id: Ibde25c59914236c67c72f3a882e66b03645f8789 --- src/hackney_url.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hackney_url.erl b/src/hackney_url.erl index bd9c063c..2ebe19a5 100644 --- a/src/hackney_url.erl +++ b/src/hackney_url.erl @@ -52,7 +52,8 @@ parse_url(URL) -> parse_url(URL, #hackney_url{transport=hackney_tcp, scheme=http}). parse_url(URL, S) -> - {URL1, Fragment} = parse_fragment(URL), + URL0 = parse_protocol(URL), + {URL1, Fragment} = parse_fragment(URL0), case binary:split(URL1, <<"/">>) of [URL1] -> parse_addr1(URL1, S#hackney_url{raw_path = raw_fragment(Fragment), @@ -277,6 +278,14 @@ parse_fragment(S) -> {S1, F} end. +parse_protocol(S) -> + case binary:split(S, <<"://">>) of + [Url] -> + Url; + [_InvalidProtocol, Url] -> + Url + end. + %% @doc Decode an URL encoded binary. %% @equiv urldecode(Bin, crash)