Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/changelog.d/notification-filter-nil-content.fix b/changelog.d/notification-filter-nil-content.fix
new file mode 100644
index 000000000..56b3ad6d1
--- /dev/null
+++ b/changelog.d/notification-filter-nil-content.fix
@@ -0,0 +1 @@
+Do not crash when creating notifications for posts without content while the user has filters
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index afd750823..6e4a97a25 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -821,6 +821,9 @@ defmodule Pleroma.Notification do
object.data["actor"] == user.ap_id ->
false
+ not is_binary(object.data["content"]) ->
+ false
+
not is_nil(regex = Pleroma.Filter.compose_regex(user, :re)) ->
Regex.match?(regex, object.data["content"])
diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs
index 992b15f8b..1ff014a8d 100644
--- a/test/pleroma/notification_test.exs
+++ b/test/pleroma/notification_test.exs
@@ -9,6 +9,7 @@ defmodule Pleroma.NotificationTest do
alias Pleroma.FollowingRelationship
alias Pleroma.Notification
+ alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
@@ -276,6 +277,22 @@ defmodule Pleroma.NotificationTest do
assert {:ok, []} == Notification.create_notifications(status)
end
+ test "it creates notifications for objects without content when the user has filters" do
+ author = insert(:user)
+ user = insert(:user)
+ insert(:filter, user: user, phrase: "cofe", hide: true)
+
+ {:ok, status} = CommonAPI.post(author, %{status: "hey @#{user.nickname}"})
+ object = Object.normalize(status, fetch: false)
+
+ {:ok, _} =
+ object
+ |> Object.change(%{data: Map.delete(object.data, "content")})
+ |> Object.update_and_set_cache()
+
+ assert {:ok, [_]} = Notification.create_notifications(Pleroma.Activity.get_by_id(status.id))
+ end
+
test "it creates notifications if content matches with a not irreversible filter" do
user = insert(:user)
subscriber = insert(:user)

File Metadata

Mime Type
text/x-diff
Expires
Thu, Oct 29, 5:36 AM (9 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1797590
Default Alt Text
(2 KB)

Event Timeline