summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Felder <feld@FreeBSD.org>2020-11-12 10:04:32 -0600
committerMark Felder <feld@feld.me>2021-05-11 16:50:11 -0500
commit2b231eeaf99ed7df1433b986aff4869c9d0c512a (patch)
treee0ddd3e50a17937816e4a6e23cb232bd84f77551
parent9b12bff1eb9b8d3d0d1ff9e79066266705950ff6 (diff)
Add trimming of punctuation that may cause matches to fail
-rw-r--r--lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex15
1 files 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 =