From 9b12bff1eb9b8d3d0d1ff9e79066266705950ff6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 12 Nov 2020 09:26:47 -0600 Subject: Make sure matches work on whole words, case insensitive. --- lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex | 11 +++++++++-- 1 file 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 -- cgit v1.2.3