From 24f40b8a26f95ee7f50b6023176d361660ceb35c Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov <ivantashkinov@gmail.com>
Date: Sat, 30 May 2020 10:29:08 +0300
Subject: [PATCH] [#1794] Fixed search query splitting regex to deal with
 Unicode. Adjusted a test.

---
 lib/pleroma/web/mastodon_api/controllers/search_controller.ex | 2 +-
 test/web/mastodon_api/controllers/search_controller_test.exs  | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex
index 23fe378a6..8840fc19c 100644
--- a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex
@@ -124,7 +124,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
   defp prepare_tags(query, add_joined_tag \\ true) do
     tags =
       query
-      |> String.split(~r/[^#\w]+/, trim: true)
+      |> String.split(~r/[^#\w]+/u, trim: true)
       |> Enum.uniq_by(&String.downcase/1)
 
     explicit_tags = Enum.filter(tags, fn tag -> String.starts_with?(tag, "#") end)
diff --git a/test/web/mastodon_api/controllers/search_controller_test.exs b/test/web/mastodon_api/controllers/search_controller_test.exs
index 498290377..84d46895e 100644
--- a/test/web/mastodon_api/controllers/search_controller_test.exs
+++ b/test/web/mastodon_api/controllers/search_controller_test.exs
@@ -71,6 +71,10 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
         get(conn, "/api/v2/search?q=天子")
         |> json_response_and_validate_schema(200)
 
+      assert results["hashtags"] == [
+               %{"name" => "天子", "url" => "#{Web.base_url()}/tag/天子"}
+             ]
+
       [status] = results["statuses"]
       assert status["id"] == to_string(activity.id)
     end