aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2020-06-11 14:04:51 +0000
committerfeld <feld@feld.me>2020-06-11 14:04:51 +0000
commit5d6ec6e5fc9b00d367568dd111816b90cddad02b (patch)
treebabf4d13ab2bfde56c17d7e1a8c6d7e690a58de3 /lib
parent7aa6c82937090ca6f2298dee0ef894954ca2f129 (diff)
parentb28cec4271c52d55f6e6cf8a1bcdb41efec3ef03 (diff)
downloadpleroma-5d6ec6e5fc9b00d367568dd111816b90cddad02b.tar.gz
Merge branch '1794-hashtags-construction-from-uri' into 'develop'
[#1794] Hashtags search fix for URI as query string Closes #1794 See merge request pleroma/pleroma!2641
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/search_controller.ex14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex
index 8840fc19c..46bcf4228 100644
--- a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex
@@ -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)