[#1794] Fixes URI query handling for hashtags extraction in search.
This commit is contained in:
parent
7aa6c82937
commit
b28cec4271
2 changed files with 23 additions and 0 deletions
|
|
@ -124,6 +124,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
|
|||
defp prepare_tags(query, add_joined_tag \\ true) do
|
||||
tags =
|
||||
query
|
||||
|> preprocess_uri_query()
|
||||
|> String.split(~r/[^#\w]+/u, trim: true)
|
||||
|> Enum.uniq_by(&String.downcase/1)
|
||||
|
||||
|
|
@ -147,6 +148,19 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
|
|||
end
|
||||
end
|
||||
|
||||
# If `query` is a URI, returns last component of its path, otherwise returns `query`
|
||||
defp preprocess_uri_query(query) do
|
||||
if query =~ ~r/https?:\/\// do
|
||||
query
|
||||
|> URI.parse()
|
||||
|> Map.get(:path)
|
||||
|> String.split("/")
|
||||
|> Enum.at(-1)
|
||||
else
|
||||
query
|
||||
end
|
||||
end
|
||||
|
||||
defp joined_tag(tags) do
|
||||
tags
|
||||
|> Enum.map(fn tag -> String.capitalize(tag) end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue