From 5b23dfa1c5e6a3ec30fc6dc32761f27968eabf2f Mon Sep 17 00:00:00 2001 From: cascode Date: Fri, 4 Jan 2019 01:35:26 -0800 Subject: [PATCH 1/3] handle null --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1edded415..0e5e2d943 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -610,7 +610,7 @@ def search(query, resolve \\ false) do select_merge: %{ search_distance: fragment( - "? <-> (? || ?)", + "? <-> (? || coalesce(?, ''))", ^query, u.nickname, u.name From ab6ebbae67c307e007806daa68a4217511bf4ed2 Mon Sep 17 00:00:00 2001 From: cascode Date: Fri, 4 Jan 2019 10:14:13 -0800 Subject: [PATCH 2/3] added test for #499 --- test/user_test.exs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/user_test.exs b/test/user_test.exs index 869e9196d..4f4f55f90 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -756,5 +756,13 @@ test "finds a user, ranking by similarity" do assert user_four == User.search("lain@ple") |> List.first() |> Map.put(:search_distance, nil) end + + test "finds a user whose name is nil" do + _user = insert(:user, %{name: "notamatch", nickname: "testuser@pleroma.amplifie.red"}) + user_two = insert(:user, %{name: nil, nickname: "lain@pleroma.soykaf.com"}) + + assert user_two == + User.search("lain@pleroma.soykaf.com") |> List.first() |> Map.put(:search_distance, nil) + end end end From 4c5ee4c62bb68982bf286b302dec77468a6d19b5 Mon Sep 17 00:00:00 2001 From: cascode Date: Fri, 4 Jan 2019 10:18:43 -0800 Subject: [PATCH 3/3] formatted --- test/user_test.exs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/user_test.exs b/test/user_test.exs index 4f4f55f90..74accb7c8 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -762,7 +762,9 @@ test "finds a user whose name is nil" do user_two = insert(:user, %{name: nil, nickname: "lain@pleroma.soykaf.com"}) assert user_two == - User.search("lain@pleroma.soykaf.com") |> List.first() |> Map.put(:search_distance, nil) + User.search("lain@pleroma.soykaf.com") + |> List.first() + |> Map.put(:search_distance, nil) end end end