more careful checking of parameter values, fixes #75

This commit is contained in:
byte[] 2020-04-05 11:56:53 -04:00
parent 19442633c6
commit d09d77c0cd
2 changed files with 10 additions and 1 deletions

View file

@ -12,6 +12,10 @@ defmodule PhilomenaWeb.CommissionController do
commission_search(params["commission"]) commission_search(params["commission"])
|> Repo.paginate(conn.assigns.scrivener) |> 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", render(conn, "index.html",
title: "Commissions", title: "Commissions",
commissions: commissions, commissions: commissions,
@ -78,6 +82,9 @@ defmodule PhilomenaWeb.CommissionController do
defp presence([]), defp presence([]),
do: nil do: nil
defp permit_map(x) when is_map(x), do: x
defp permit_map(_), do: nil
defp presence(string) when is_binary(string), defp presence(string) when is_binary(string),
do: if(String.trim(string) == "", do: nil, else: string) do: if(String.trim(string) == "", do: nil, else: string)

View file

@ -19,7 +19,7 @@ defmodule PhilomenaWeb.DuplicateReportController do
def index(conn, params) do def index(conn, params) do
states = states =
(params["states"] || ~W(open claimed)) (presence(params["states"]) || ~W(open claimed))
|> wrap() |> wrap()
|> Enum.filter(&Enum.member?(@valid_states, &1)) |> 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(list) when is_list(list), do: list
defp wrap(not_a_list), do: [not_a_list] defp wrap(not_a_list), do: [not_a_list]
defp presence(""), do: nil
defp presence(x), do: x
end end