Browse Source

fix case when tags is invalid

tags/v0.9.9
Maksim Pechnikov 5 years ago
parent
commit
ea72ac549b
2 changed files with 15 additions and 2 deletions
  1. +3
    -1
      lib/pleroma/web/mastodon_api/views/status_view.ex
  2. +12
    -1
      test/web/mastodon_api/status_view_test.exs

+ 3
- 1
lib/pleroma/web/mastodon_api/views/status_view.ex View 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)


+ 12
- 1
test/web/mastodon_api/status_view_test.exs View 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"}


Loading…
Cancel
Save