From 52ed287e87ea18fdbf14695ccfafae00768299dc Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 18 Apr 2019 21:17:52 +0300 Subject: [PATCH] Fix incorrect multiple emoji tag handling introduced in initial impl --- lib/pleroma/emoji.ex | 13 ++++++------- .../web/mastodon_api/mastodon_api_controller.ex | 2 +- .../web/twitter_api/controllers/util_controller.ex | 2 +- test/emoji_test.exs | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex index 9a23bd81b..15455b779 100644 --- a/lib/pleroma/emoji.ex +++ b/lib/pleroma/emoji.ex @@ -147,8 +147,7 @@ defp load_pack(pack_dir) do |> Enum.map(fn {shortcode, rel_file} -> filename = Path.join(common_pack_path, rel_file) - # If no tag matches, use the pack name as a tag - {shortcode, filename, to_string(match_extra(@groups, filename))} + {shortcode, filename, [to_string(match_extra(@groups, filename))]} end) end end @@ -190,11 +189,11 @@ defp load_from_file_stream(stream) do |> Stream.map(&String.trim/1) |> Stream.map(fn line -> case String.split(line, ~r/,\s*/) do - [name, file, tags] -> - {name, file, tags} - [name, file] -> - {name, file, to_string(match_extra(@groups, file))} + {name, file, [to_string(match_extra(@groups, file))]} + + [name, file | tags] -> + {name, file, tags} _ -> nil @@ -217,7 +216,7 @@ defp load_from_globs(globs) do tag = match_extra(@groups, Path.join("/", Path.relative_to(path, static_path))) shortcode = Path.basename(path, Path.extname(path)) external_path = Path.join("/", Path.relative_to(path, static_path)) - {shortcode, external_path, to_string(tag)} + {shortcode, external_path, [to_string(tag)]} end) end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 3916d7c41..2a81dcc67 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -190,7 +190,7 @@ defp mastodonized_emoji do "static_url" => url, "visible_in_picker" => true, "url" => url, - "tags" => String.split(tags, ",") + "tags" => tags } end) end diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 9441984c7..8665e058a 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -286,7 +286,7 @@ def emoji(conn, _params) do emoji = Emoji.get_all() |> Enum.map(fn {short_code, path, tags} -> - {short_code, %{image_url: path, tags: String.split(tags, ",")}} + {short_code, %{image_url: path, tags: tags}} end) |> Enum.into(%{}) diff --git a/test/emoji_test.exs b/test/emoji_test.exs index cb1d62d00..2eaa26be6 100644 --- a/test/emoji_test.exs +++ b/test/emoji_test.exs @@ -15,7 +15,7 @@ test "first emoji", %{emoji_list: emoji_list} do assert tuple_size(emoji) == 3 assert is_binary(code) assert is_binary(path) - assert is_binary(tags) + assert is_list(tags) end test "random emoji", %{emoji_list: emoji_list} do @@ -25,7 +25,7 @@ test "random emoji", %{emoji_list: emoji_list} do assert tuple_size(emoji) == 3 assert is_binary(code) assert is_binary(path) - assert is_binary(tags) + assert is_list(tags) end end