mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
guard against invalid complex filters
This commit is contained in:
parent
08e95e0a01
commit
ffdddb3f68
1 changed files with 9 additions and 2 deletions
|
@ -14,8 +14,8 @@ defmodule PhilomenaWeb.ImageFilterPlug do
|
|||
filter = conn.assigns[:current_filter]
|
||||
|
||||
tag_exclusion = %{terms: %{tag_ids: filter.hidden_tag_ids}}
|
||||
{:ok, query_exclusion} = Query.compile(user, normalize(filter.hidden_complex_str))
|
||||
{:ok, query_spoiler} = Query.compile(user, normalize(filter.spoilered_complex_str))
|
||||
query_exclusion = invalid_filter_guard(user, filter.hidden_complex_str)
|
||||
query_spoiler = invalid_filter_guard(user, filter.spoilered_complex_str)
|
||||
|
||||
query = %{
|
||||
bool: %{
|
||||
|
@ -28,4 +28,11 @@ defmodule PhilomenaWeb.ImageFilterPlug do
|
|||
|> assign(:compiled_complex_spoiler, query_spoiler)
|
||||
|> assign(:compiled_filter, query)
|
||||
end
|
||||
|
||||
defp invalid_filter_guard(user, search_string) do
|
||||
case Query.compile(user, normalize(search_string)) do
|
||||
{:ok, query} -> query
|
||||
_error -> %{match_all: %{}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue