diff --git a/mix.exs b/mix.exs index fbed459a4..9da7885b5 100644 --- a/mix.exs +++ b/mix.exs @@ -87,6 +87,7 @@ defmodule Ejabberd.MixProject do if_version_below('23', [{:d, :USE_OLD_PG2}]) ++ if_version_below('24', [{:d, :COMPILER_REPORTS_ONLY_LINES}]) ++ if_version_below('24', [{:d, :SYSTOOLS_APP_DEF_WITHOUT_OPTIONAL}]) ++ + if_function_exported(:uri_string, :normalize, 1, [{:d, :HAVE_URI_STRING}]) if_function_exported(:erl_error, :format_exception, 6, [{:d, :HAVE_ERL_ERROR}]) defines = for {:d, value} <- result, do: {:d, value} result ++ [{:d, :ALL_DEFS, defines}] diff --git a/rebar.config b/rebar.config index 3490d976c..4be211e25 100644 --- a/rebar.config +++ b/rebar.config @@ -110,6 +110,7 @@ {if_var_true, sip, {d, 'SIP'}}, {if_var_true, stun, {d, 'STUN'}}, {if_have_fun, {erl_error, format_exception, 6}, {d, 'HAVE_ERL_ERROR'}}, + {if_have_fun, {uri_string, normalize, 1}, {d, 'HAVE_URI_STRING'}}, {src_dirs, [src, {if_rebar3, sql}, {if_var_true, tools, tools}, diff --git a/src/rest.erl b/src/rest.erl index 038ec1fb1..1bb5c5ef7 100644 --- a/src/rest.erl +++ b/src/rest.erl @@ -191,6 +191,18 @@ base_url(Server, Path) -> _ -> Url end. +-ifdef(HAVE_URI_STRING). +uri_hack(Str) -> + case uri_string:normalize("%25") of + "%" -> % This hack around bug in httpc >21 <23.2 + binary:replace(Str, <<"%25">>, <<"%2525">>, [global]); + _ -> Str + end. +-else. +uri_hack(Str) -> + Str. +-endif. + url(Url, []) -> Url; url(Url, Params) -> @@ -198,17 +210,7 @@ url(Url, Params) -> (misc:url_encode(Value))/binary>> || {Key, Value} <- Params], <<$&, Encoded0/binary>> = iolist_to_binary(L), - Encoded = - case erlang:function_exported(uri_string, normalize, 1) of - true -> - case uri_string:normalize("%25") of - "%" -> % This hack around bug in httpc >21 <23.2 - binary:replace(Encoded0, <<"%25">>, <<"%2525">>, [global]); - _ -> Encoded0 - end; - _ -> - Encoded0 - end, + Encoded = uri_hack(Encoded0), <>. url(Server, Path, Params) -> case binary:split(base_url(Server, Path), <<"?">>) of