diff options
author | Mark Felder <feld@FreeBSD.org> | 2020-11-12 09:26:47 -0600 |
---|---|---|
committer | Mark Felder <feld@feld.me> | 2021-05-11 16:50:11 -0500 |
commit | 9b12bff1eb9b8d3d0d1ff9e79066266705950ff6 (patch) | |
tree | 365bdd4f25c07c9dcb13d3192bfd004b4f1dd88c | |
parent | 83574e54485ec96de7ae933182a1a72a4b891e06 (diff) | |
download | pleroma-9b12bff1eb9b8d3d0d1ff9e79066266705950ff6.tar.gz |
Make sure matches work on whole words, case insensitive.
-rw-r--r-- | lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex | 11 |
1 files changed, 9 insertions, 2 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 a882ec8d6..c832ae169 100644 --- a/lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex @@ -48,8 +48,15 @@ defmodule Pleroma.Web.ActivityPub.MRF.AutoSubjectPolicy do defp check_subject(message), do: {:ok, message} - defp string_matches?(content, pattern) when is_binary(content) do - String.contains?(content, pattern) + defp string_matches?(content, keywords) when is_list(keywords) do + wordlist = content |> String.downcase() |> String.split(" ", trim: true) |> Enum.uniq() + + 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() + String.downcase(keyword) in wordlist end defp check_match(%{"object" => %{} = object} = message) do |