Merge branch 'fix/emoji-encoding' into 'develop'

URI.encode custom emojis

Closes #2381

See merge request pleroma/pleroma!3235
This commit is contained in:
lain 2021-01-05 20:09:29 +00:00
commit 18296c7473
4 changed files with 17 additions and 1 deletions

View file

@ -1,2 +1,3 @@
firefox, /emoji/Firefox.gif, Gif,Fun firefox, /emoji/Firefox.gif, Gif,Fun
blank, /emoji/blank.png, Fun blank, /emoji/blank.png, Fun
dinosaur, /emoji/dino walking.gif, Gif

View file

@ -919,7 +919,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
defp build_emoji_tag({name, url}) do defp build_emoji_tag({name, url}) do
%{ %{
"icon" => %{"url" => url, "type" => "Image"}, "icon" => %{"url" => "#{URI.encode(url)}", "type" => "Image"},
"name" => ":" <> name <> ":", "name" => ":" <> name <> ":",
"type" => "Emoji", "type" => "Emoji",
"updated" => "1970-01-01T00:00:00Z", "updated" => "1970-01-01T00:00:00Z",

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -281,6 +281,21 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data) {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
end end
test "custom emoji urls are URI encoded" do
# :dinosaur: filename has a space -> dino walking.gif
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"})
{:ok, prepared} = Transmogrifier.prepare_outgoing(activity.data)
assert length(prepared["object"]["tag"]) == 1
url = prepared["object"]["tag"] |> List.first() |> Map.get("icon") |> Map.get("url")
assert url == "http://localhost:4001/emoji/dino%20walking.gif"
end
end end
describe "user upgrade" do describe "user upgrade" do