support for idna domains

This commit is contained in:
Alexander Strizhakov 2019-07-10 15:23:25 +00:00 committed by kaniini
commit a237c6a2d4
6 changed files with 133 additions and 3 deletions

View file

@ -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 <> ":*"))