philomena/lib/philomena_web/plugs/recode_parameter_plug.ex
2020-01-10 23:20:19 -05:00

18 lines
402 B
Elixir

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", "+")
|> String.replace("%25", "%")
params = Map.put(conn.params, name, fixed_value)
%{conn | params: params}
end
end