From 2b231eeaf99ed7df1433b986aff4869c9d0c512a Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 12 Nov 2020 10:04:32 -0600 Subject: Add trimming of punctuation that may cause matches to fail --- lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex b/lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex index c832ae169..4b8e8625a 100644 --- a/lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex @@ -49,13 +49,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.AutoSubjectPolicy do defp check_subject(message), do: {:ok, message} defp string_matches?(content, keywords) when is_list(keywords) do - wordlist = content |> String.downcase() |> String.split(" ", trim: true) |> Enum.uniq() - + wordlist = content |> make_wordlist |> trim_punct Enum.any?(keywords, fn match -> String.downcase(match) in wordlist end) end defp string_matches?(content, keyword) when is_binary(keyword) do - wordlist = content |> String.downcase() |> String.split(" ", trim: true) |> Enum.uniq() + wordlist = content |> make_wordlist |> trim_punct String.downcase(keyword) in wordlist end @@ -77,6 +76,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.AutoSubjectPolicy do {:ok, message} end + defp make_wordlist(content), + do: + content + |> String.downcase() + |> String.split(" ", trim: true) + |> Enum.uniq() + + defp trim_punct(wordlist) when is_list(wordlist), + do: wordlist |> Enum.map(fn word -> String.replace(word, ~r/[.?!:;]+$/, "") end) + @impl true def describe do mrf_autosubject = -- cgit v1.2.3