diff options
Diffstat (limited to 'lib/pleroma/user')
-rw-r--r-- | lib/pleroma/user/search.ex | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/pleroma/user/search.ex b/lib/pleroma/user/search.ex index 64eb6d2bc..e0fc6daa6 100644 --- a/lib/pleroma/user/search.ex +++ b/lib/pleroma/user/search.ex @@ -18,8 +18,7 @@ defmodule Pleroma.User.Search do for_user = Keyword.get(opts, :for_user) - # Strip the beginning @ off if there is a query - query_string = String.trim_leading(query_string, "@") + query_string = format_query(query_string) maybe_resolve(resolve, for_user, query_string) @@ -40,6 +39,18 @@ defmodule Pleroma.User.Search do results end + defp format_query(query_string) do + # Strip the beginning @ off if there is a query + query_string = String.trim_leading(query_string, "@") + + with [name, domain] <- String.split(query_string, "@"), + formatted_domain <- String.replace(domain, ~r/[!-\-|@|[-`|{-~|\/|:]+/, "") do + name <> "@" <> to_string(:idna.encode(formatted_domain)) + else + _ -> query_string + end + end + defp search_query(query_string, for_user, following) do for_user |> base_query(following) @@ -151,7 +162,7 @@ defmodule Pleroma.User.Search do defp fts_search_subquery(query, term) do processed_query = String.trim_trailing(term, "@" <> local_domain()) - |> String.replace(~r/\W+/, " ") + |> String.replace(~r/[!-\/|@|[-`|{-~|:-?]+/, " ") |> String.trim() |> String.split() |> Enum.map(&(&1 <> ":*")) |