philomena/lib/philomena_web/plugs/recode_parameter_plug.ex

17 lines
367 B
Elixir
Raw Normal View History

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