Remove spaces from the domain search
authorSergey Suprunenko <suprunenko.s@gmail.com>
Sat, 3 Aug 2019 18:13:20 +0000 (18:13 +0000)
committerkaniini <ariadne@dereferenced.org>
Sat, 3 Aug 2019 18:13:20 +0000 (18:13 +0000)
lib/pleroma/user/search.ex
test/web/mastodon_api/search_controller_test.exs

index 46620b89acf42517429aa6a1e1cb1f77d0d95c73..6fb2c2352f8aa9655f635ffc687ae40fb26f95ad 100644 (file)
@@ -44,7 +44,7 @@ defmodule Pleroma.User.Search do
     query_string = String.trim_leading(query_string, "@")
 
     with [name, domain] <- String.split(query_string, "@"),
-         formatted_domain <- String.replace(domain, ~r/[!-\-|@|[-`|{-~|\/|:]+/, "") do
+         formatted_domain <- String.replace(domain, ~r/[!-\-|@|[-`|{-~|\/|:|\s]+/, "") do
       name <> "@" <> to_string(:idna.encode(formatted_domain))
     else
       _ -> query_string
index 043b96c1413d2c425f21e136d04b0a50fb2c84b6..49c79ff0a799140717d44002d78b94681b423d2a 100644 (file)
@@ -95,6 +95,18 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
 
       assert user_three.nickname in result_ids
     end
+
+    test "returns account if query contains a space", %{conn: conn} do
+      user = insert(:user, %{nickname: "shp@shitposter.club"})
+
+      results =
+        conn
+        |> assign(:user, user)
+        |> get("/api/v1/accounts/search", %{"q" => "shp@shitposter.club xxx "})
+        |> json_response(200)
+
+      assert length(results) == 1
+    end
   end
 
   describe ".search" do