fix case when tags is invalid
authorMaksim Pechnikov <parallel588@gmail.com>
Fri, 14 Dec 2018 19:56:37 +0000 (22:56 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Fri, 14 Dec 2018 20:16:12 +0000 (23:16 +0300)
lib/pleroma/web/mastodon_api/views/status_view.ex
test/web/mastodon_api/status_view_test.exs

index f2a47f594aa182903a4ff53656150525b523de14..46c559e3ac0740687f64e24064d701e62e63dcf6 100644 (file)
@@ -244,8 +244,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
    {"name": "nextcloud", "url": "/tag/nextcloud"}]
 
   """
-  @spec build_tags(list(String.t())) :: list(map())
+  @spec build_tags(list(any())) :: list(map())
   def build_tags(object_tags) when is_list(object_tags) do
+    object_tags = for tag when is_binary(tag) <- object_tags, do: tag
+
     Enum.reduce(object_tags, [], fn tag, tags ->
       tags ++ [%{name: tag, url: "/tag/#{tag}"}]
     end)
index 4f9805c78cc446e0f571a73747b1795152cb0ef1..b7ac92760a35a6f23c9c9e1fd80a71e32ee795e1 100644 (file)
@@ -159,7 +159,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
 
   describe "build_tags/1" do
     test "it returns a a dictionary tags" do
-      assert StatusView.build_tags(["fediverse", "mastodon", "nextcloud"]) == [
+      object_tags = [
+        "fediverse",
+        "mastodon",
+        "nextcloud",
+        %{
+          "href" => "https://kawen.space/users/lain",
+          "name" => "@lain@kawen.space",
+          "type" => "Mention"
+        }
+      ]
+
+      assert StatusView.build_tags(object_tags) == [
                %{name: "fediverse", url: "/tag/fediverse"},
                %{name: "mastodon", url: "/tag/mastodon"},
                %{name: "nextcloud", url: "/tag/nextcloud"}