mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 16:40:29 +00:00
Transmogrifier: filtering weirdness in address fields
This commit is contained in:
parent
11dd29ef3f
commit
b221b640a2
2 changed files with 31 additions and 6 deletions
|
@ -62,15 +62,17 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
def fix_summary(object), do: Map.put(object, "summary", "")
|
def fix_summary(object), do: Map.put(object, "summary", "")
|
||||||
|
|
||||||
def fix_addressing_list(map, field) do
|
def fix_addressing_list(map, field) do
|
||||||
cond do
|
addrs = map[field]
|
||||||
is_binary(map[field]) ->
|
|
||||||
Map.put(map, field, [map[field]])
|
|
||||||
|
|
||||||
is_nil(map[field]) ->
|
cond do
|
||||||
Map.put(map, field, [])
|
is_list(addrs) ->
|
||||||
|
Map.put(map, field, Enum.filter(addrs, &is_binary/1))
|
||||||
|
|
||||||
|
is_binary(addrs) ->
|
||||||
|
Map.put(map, field, [addrs])
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
map
|
Map.put(map, field, [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -774,6 +774,29 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||||
assert [user.follower_address] == activity.data["to"]
|
assert [user.follower_address] == activity.data["to"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it correctly processes messages with weirdness in address fields" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
message = %{
|
||||||
|
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||||
|
"to" => [nil, user.follower_address],
|
||||||
|
"cc" => ["https://www.w3.org/ns/activitystreams#Public", ["¿"]],
|
||||||
|
"type" => "Create",
|
||||||
|
"object" => %{
|
||||||
|
"content" => "…",
|
||||||
|
"type" => "Note",
|
||||||
|
"attributedTo" => user.ap_id,
|
||||||
|
"inReplyTo" => nil
|
||||||
|
},
|
||||||
|
"actor" => user.ap_id
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||||
|
|
||||||
|
assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]
|
||||||
|
assert [user.follower_address] == activity.data["to"]
|
||||||
|
end
|
||||||
|
|
||||||
test "it accepts Move activities" do
|
test "it accepts Move activities" do
|
||||||
old_user = insert(:user)
|
old_user = insert(:user)
|
||||||
new_user = insert(:user)
|
new_user = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue