From 505e58d4eb84226613c85ac526c591dab5b1307e Mon Sep 17 00:00:00 2001 From: tusooa Date: Mon, 22 May 2023 08:14:20 -0400 Subject: [PATCH 1/3] Fix ObjectTest --- lib/pleroma/object/updater.ex | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/object/updater.ex b/lib/pleroma/object/updater.ex index bad811965..269609f1b 100644 --- a/lib/pleroma/object/updater.ex +++ b/lib/pleroma/object/updater.ex @@ -100,12 +100,14 @@ defmodule Pleroma.Object.Updater do end defp maybe_update_poll(to_be_updated, updated_object) do - choice_key = fn data -> - if Map.has_key?(data, "anyOf"), do: "anyOf", else: "oneOf" + choice_key = fn + %{"anyOf" => [_ | _]} = data -> "anyOf" + %{"oneOf" => [_ | _]} = data -> "oneOf" + _ -> nil end with true <- to_be_updated["type"] == "Question", - key <- choice_key.(updated_object), + key when not is_nil(key) <- choice_key.(updated_object), true <- key == choice_key.(to_be_updated), orig_choices <- to_be_updated[key] |> Enum.map(&Map.drop(&1, ["replies"])), new_choices <- updated_object[key] |> Enum.map(&Map.drop(&1, ["replies"])), From 6aafa7fe7661bcf9e62c16381ffeb2d32ec9bafa Mon Sep 17 00:00:00 2001 From: tusooa Date: Mon, 22 May 2023 08:16:14 -0400 Subject: [PATCH 2/3] Add changelog --- changelog.d/fix-object-test.fix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/fix-object-test.fix diff --git a/changelog.d/fix-object-test.fix b/changelog.d/fix-object-test.fix new file mode 100644 index 000000000..5eea719f0 --- /dev/null +++ b/changelog.d/fix-object-test.fix @@ -0,0 +1 @@ +Correctly handle the situation when a poll has both "anyOf" and "oneOf" but one of them being empty From 819a82da99588b53a67f42d8572a2484c4f17d40 Mon Sep 17 00:00:00 2001 From: tusooa Date: Mon, 22 May 2023 08:19:58 -0400 Subject: [PATCH 3/3] Fix unused variable --- lib/pleroma/object/updater.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/object/updater.ex b/lib/pleroma/object/updater.ex index 269609f1b..b1e4870ba 100644 --- a/lib/pleroma/object/updater.ex +++ b/lib/pleroma/object/updater.ex @@ -101,8 +101,8 @@ defmodule Pleroma.Object.Updater do defp maybe_update_poll(to_be_updated, updated_object) do choice_key = fn - %{"anyOf" => [_ | _]} = data -> "anyOf" - %{"oneOf" => [_ | _]} = data -> "oneOf" + %{"anyOf" => [_ | _]} -> "anyOf" + %{"oneOf" => [_ | _]} -> "oneOf" _ -> nil end