summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Chmielowski <pawel@process-one.net>2021-12-06 15:46:52 +0100
committerPaweł Chmielowski <pawel@process-one.net>2021-12-06 15:46:52 +0100
commit8d8a3177e15aac8e693aa20e8e51d6463e81163d (patch)
tree07d6db0764283edb6b4455e0feb58d574dc43973
parentAdd workaround for bug in older erlang version in rest module (diff)
Eliminate xref warning from last commit
-rw-r--r--mix.exs1
-rw-r--r--rebar.config1
-rw-r--r--src/rest.erl24
3 files changed, 15 insertions, 11 deletions
diff --git a/mix.exs b/mix.exs
index fbed459a..9da7885b 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 3490d976..4be211e2 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 038ec1fb..1bb5c5ef 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/binary, $?, Encoded/binary>>.
url(Server, Path, Params) ->
case binary:split(base_url(Server, Path), <<"?">>) of