logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: 2a9191a53eda9a2e1b067774804db54fc3eda5d0
parent: 8e9f6d8f6954f3eb3f3b4b371ae9e886d88e2f0d
Author: rinpatch <rinpatch@sdf.org>
Date:   Thu,  7 Mar 2019 16:42:05 +0000

Merge branch 'bugfix/mrf-antifollowbot-nil-bio' into 'develop'

MRF: anti followbot: gracefully handle nil display names

See merge request pleroma/pleroma!909

Diffstat:

Mlib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex12+++++++++---
Mtest/web/activity_pub/mrf/anti_followbot_policy_test.exs15+++++++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex b/lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex @@ -23,15 +23,21 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do defp score_displayname(_), do: 0.0 defp determine_if_followbot(%User{nickname: nickname, name: displayname}) do + # nickname will always be a binary string because it's generated by Pleroma. nick_score = nickname |> String.downcase() |> score_nickname() + # displayname will either be a binary string or nil, if a displayname isn't set. name_score = - displayname - |> String.downcase() - |> score_displayname() + if is_binary(displayname) do + displayname + |> String.downcase() + |> score_displayname() + else + 0.0 + end nick_score + name_score end diff --git a/test/web/activity_pub/mrf/anti_followbot_policy_test.exs b/test/web/activity_pub/mrf/anti_followbot_policy_test.exs @@ -54,4 +54,19 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do {:ok, _} = AntiFollowbotPolicy.filter(message) end + + test "it gracefully handles nil display names" do + actor = insert(:user, %{name: nil}) + target = insert(:user) + + message = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "type" => "Follow", + "actor" => actor.ap_id, + "object" => target.ap_id, + "id" => "https://example.com/activities/1234" + } + + {:ok, _} = AntiFollowbotPolicy.filter(message) + end end