diff options
author | Alexander Strizhakov <alex.strizhakov@gmail.com> | 2019-07-10 15:23:25 +0000 |
---|---|---|
committer | kaniini <nenolod@gmail.com> | 2019-07-10 15:23:25 +0000 |
commit | a237c6a2d4b60a6f15429eb860b995ed2df8d327 (patch) | |
tree | 0553b82fcb5992d0694adefe7d1351c5ce9b4591 /lib | |
parent | 3ff4a06ebe3b8fc8acaa29da0c9170d006b58987 (diff) | |
download | pleroma-a237c6a2d4b60a6f15429eb860b995ed2df8d327.tar.gz |
support for idna domains
Diffstat (limited to 'lib')
-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 <> ":*")) |