[#3213] Ignoring of blank elements from objects.data->tag.
authorIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 21 Jan 2021 17:50:06 +0000 (20:50 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 21 Jan 2021 17:50:06 +0000 (20:50 +0300)
lib/pleroma/object.ex
test/pleroma/hashtag_test.exs [new file with mode: 0644]

index 5102be1decda2ca3807bdcf9a260573c1a00f21a..9b5c1bec1782c331c608b77a04c15e6e84cc5896 100644 (file)
@@ -420,6 +420,8 @@ defmodule Pleroma.Object do
       hashtag when is_bitstring(hashtag) -> String.downcase(hashtag)
     end)
     |> Enum.uniq()
+    # Note: "" elements (plain text) might occur in `data.tag` for incoming objects
+    |> Enum.filter(&(&1 not in [nil, ""]))
   end
 
   def object_data_hashtags(_), do: []
diff --git a/test/pleroma/hashtag_test.exs b/test/pleroma/hashtag_test.exs
new file mode 100644 (file)
index 0000000..0264dea
--- /dev/null
@@ -0,0 +1,17 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.HashtagTest do
+  use Pleroma.DataCase
+
+  alias Pleroma.Hashtag
+
+  describe "changeset validations" do
+    test "ensure non-blank :name" do
+      changeset = Hashtag.changeset(%Hashtag{}, %{name: ""})
+
+      assert {:name, {"can't be blank", [validation: :required]}} in changeset.errors
+    end
+  end
+end