mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
more careful checking of parameter values, fixes #75
This commit is contained in:
parent
19442633c6
commit
d09d77c0cd
2 changed files with 10 additions and 1 deletions
|
@ -12,6 +12,10 @@ defmodule PhilomenaWeb.CommissionController do
|
|||
commission_search(params["commission"])
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
||||
# Scrub parameters to avoid form error...
|
||||
params = Map.put(conn.params, "commission", permit_map(conn.params["commission"]))
|
||||
conn = Map.put(conn, :params, params)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Commissions",
|
||||
commissions: commissions,
|
||||
|
@ -78,6 +82,9 @@ defmodule PhilomenaWeb.CommissionController do
|
|||
defp presence([]),
|
||||
do: nil
|
||||
|
||||
defp permit_map(x) when is_map(x), do: x
|
||||
defp permit_map(_), do: nil
|
||||
|
||||
defp presence(string) when is_binary(string),
|
||||
do: if(String.trim(string) == "", do: nil, else: string)
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ defmodule PhilomenaWeb.DuplicateReportController do
|
|||
|
||||
def index(conn, params) do
|
||||
states =
|
||||
(params["states"] || ~W(open claimed))
|
||||
(presence(params["states"]) || ~W(open claimed))
|
||||
|> wrap()
|
||||
|> Enum.filter(&Enum.member?(@valid_states, &1))
|
||||
|
||||
|
@ -72,4 +72,6 @@ defmodule PhilomenaWeb.DuplicateReportController do
|
|||
|
||||
defp wrap(list) when is_list(list), do: list
|
||||
defp wrap(not_a_list), do: [not_a_list]
|
||||
defp presence(""), do: nil
|
||||
defp presence(x), do: x
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue