question_validator: Allow content to be an empty-string (blank)

This commit is contained in:
Haelwenn (lanodan) Monnier 2020-08-04 14:23:35 +02:00
parent ac2598307d
commit 0f088d8ce3
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE
2 changed files with 10 additions and 1 deletions

View File

@ -111,7 +111,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionValidator do
def validate_data(data_cng) do def validate_data(data_cng) do
data_cng data_cng
|> validate_inclusion(:type, ["Question"]) |> validate_inclusion(:type, ["Question"])
|> validate_required([:id, :actor, :attributedTo, :type, :content, :context]) |> validate_required([:id, :actor, :attributedTo, :type, :context])
|> CommonValidations.validate_any_presence([:cc, :to]) |> CommonValidations.validate_any_presence([:cc, :to])
|> CommonValidations.validate_fields_match([:actor, :attributedTo]) |> CommonValidations.validate_fields_match([:actor, :attributedTo])
|> CommonValidations.validate_actor_is_active() |> CommonValidations.validate_actor_is_active()

View File

@ -111,4 +111,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
assert {:error, {:validate_object, {:error, _}}} = Transmogrifier.handle_incoming(data) assert {:error, {:validate_object, {:error, _}}} = Transmogrifier.handle_incoming(data)
end end
test "accepts a Question with no content" do
data =
File.read!("test/fixtures/mastodon-question-activity.json")
|> Poison.decode!()
|> Kernel.put_in(["object", "content"], "")
assert {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
end
end end