philomena/lib/philomena_web/plugs/recode_parameter_plug.ex

19 lines
402 B
Elixir
Raw Permalink Normal View History

2019-12-08 07:00:53 +01:00
defmodule PhilomenaWeb.RecodeParameterPlug do
def init(opts), do: opts
2020-01-11 05:20:19 +01:00
def call(conn, name: name) do
2019-12-08 07:00:53 +01:00
fixed_value =
conn
|> Map.get(:params)
|> Map.get(name)
|> to_string()
|> URI.encode_www_form()
|> String.replace("%2B", "+")
|> String.replace("%25", "%")
2019-12-08 07:00:53 +01:00
params = Map.put(conn.params, name, fixed_value)
%{conn | params: params}
end
2020-01-11 05:20:19 +01:00
end