From 5d89e0c9172b41a9c3dce8150cab4ced8e353059 Mon Sep 17 00:00:00 2001 From: Helge Date: Sun, 3 Mar 2024 09:11:45 +0100 Subject: [PATCH] Allow for url to be a list This solves interoperability issues, see: - https://git.pleroma.social/pleroma/pleroma/-/issues/3253 - https://socialhub.activitypub.rocks/t/fep-fffd-proxy-objects/3172/30?u=helge - https://data.funfedi.dev/0.1.1/#url-parameter --- .../article_note_page_validator.ex | 8 ++++++++ .../article_note_page_validator_test.exs | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex b/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex index 4d1e80868..ed1b90eab 100644 --- a/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex @@ -53,6 +53,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do defp fix_url(%{"url" => url} = data) when is_bitstring(url), do: data defp fix_url(%{"url" => url} = data) when is_map(url), do: Map.put(data, "url", url["href"]) + defp fix_url(%{"url" => url} = data) when is_list(url) do + if is_map(List.first(url)) do + Map.put(data, "url", List.first(url)["href"]) + else + Map.put(data, "url", List.first(url)) + end + end + defp fix_url(data), do: data defp fix_tag(%{"tag" => tag} = data) when is_list(tag) do diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs index bcf096a5b..1aaf9a566 100644 --- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs @@ -39,6 +39,25 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note) end + test "note with url validates", %{note: note} do + note = Map.put(note, "url", "https://remote.example/link") + %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note) + end + + test "note with url array validates", %{note: note} do + note = Map.put(note, "url", ["https://remote.example/link"]) + %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note) + end + + test "note with url array validates if contains a link object", %{note: note} do + note = Map.put(note, "url", [%{ + "type" => "Link", + "href" => "https://remote.example/link" + }]) + %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note) + end + + test "a note with a language validates" do insert(:user, %{ap_id: "https://mastodon.social/users/akkoma_ap_integration_tester"}) note = File.read!("test/fixtures/mastodon/note_with_language.json") |> Jason.decode!()