Emoji, AccountView, UtilController: Handle encoding of emoji
This commit is contained in:
parent
ee19d14b06
commit
3ef98652f7
5 changed files with 52 additions and 2 deletions
|
|
@ -199,7 +199,8 @@ defmodule Pleroma.Emoji do
|
||||||
end
|
end
|
||||||
|
|
||||||
def local_url("/" <> _ = path) do
|
def local_url("/" <> _ = path) do
|
||||||
URIEncoding.encode_url(Endpoint.url() <> path, bypass_decode: true)
|
path = URIEncoding.encode_url(path, bypass_parse: true, bypass_decode: true)
|
||||||
|
Endpoint.url() <> path
|
||||||
end
|
end
|
||||||
|
|
||||||
def local_url(path) when is_binary(path) do
|
def local_url(path) when is_binary(path) do
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.UserNote
|
alias Pleroma.UserNote
|
||||||
alias Pleroma.UserRelationship
|
alias Pleroma.UserRelationship
|
||||||
|
alias Pleroma.Utils.URIEncoding
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Web.MastodonAPI.AccountView
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
|
|
@ -238,7 +239,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
|
|
||||||
emojis =
|
emojis =
|
||||||
Enum.map(user.emoji, fn {shortcode, raw_url} ->
|
Enum.map(user.emoji, fn {shortcode, raw_url} ->
|
||||||
url = MediaProxy.url(raw_url)
|
url =
|
||||||
|
raw_url
|
||||||
|
|> encode_emoji_url()
|
||||||
|
|> MediaProxy.url()
|
||||||
|
|
||||||
%{
|
%{
|
||||||
shortcode: shortcode,
|
shortcode: shortcode,
|
||||||
|
|
@ -511,4 +515,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
# See https://git.pleroma.social/pleroma/pleroma-meta/-/issues/14
|
# See https://git.pleroma.social/pleroma/pleroma-meta/-/issues/14
|
||||||
user.actor_type == "Service" || user.actor_type == "Group"
|
user.actor_type == "Service" || user.actor_type == "Group"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp encode_emoji_url(nil), do: nil
|
||||||
|
defp encode_emoji_url("http" <> _ = url), do: URIEncoding.encode_url(url)
|
||||||
|
|
||||||
|
defp encode_emoji_url("/" <> _ = path),
|
||||||
|
do: URIEncoding.encode_url(path, bypass_parse: true, bypass_decode: true)
|
||||||
|
|
||||||
|
defp encode_emoji_url(path) when is_binary(path),
|
||||||
|
do: URIEncoding.encode_url(path, bypass_parse: true, bypass_decode: true)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.Emoji
|
alias Pleroma.Emoji
|
||||||
alias Pleroma.Healthcheck
|
alias Pleroma.Healthcheck
|
||||||
|
alias Pleroma.Utils.URIEncoding
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.Auth.WrapperAuthenticator, as: Authenticator
|
alias Pleroma.Web.Auth.WrapperAuthenticator, as: Authenticator
|
||||||
|
|
@ -180,12 +181,22 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
||||||
def emoji(conn, _params) do
|
def emoji(conn, _params) do
|
||||||
emoji =
|
emoji =
|
||||||
Enum.reduce(Emoji.get_all(), %{}, fn {code, %Emoji{file: file, tags: tags}}, acc ->
|
Enum.reduce(Emoji.get_all(), %{}, fn {code, %Emoji{file: file, tags: tags}}, acc ->
|
||||||
|
file = encode_emoji_url(file)
|
||||||
Map.put(acc, code, %{image_url: file, tags: tags})
|
Map.put(acc, code, %{image_url: file, tags: tags})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
json(conn, emoji)
|
json(conn, emoji)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp encode_emoji_url(nil), do: nil
|
||||||
|
defp encode_emoji_url("http" <> _ = url), do: URIEncoding.encode_url(url)
|
||||||
|
|
||||||
|
defp encode_emoji_url("/" <> _ = path),
|
||||||
|
do: URIEncoding.encode_url(path, bypass_parse: true, bypass_decode: true)
|
||||||
|
|
||||||
|
defp encode_emoji_url(path) when is_binary(path),
|
||||||
|
do: URIEncoding.encode_url(path, bypass_parse: true, bypass_decode: true)
|
||||||
|
|
||||||
def update_notification_settings(%{assigns: %{user: user}} = conn, params) do
|
def update_notification_settings(%{assigns: %{user: user}} = conn, params) do
|
||||||
with {:ok, _} <- User.update_notification_settings(user, params) do
|
with {:ok, _} <- User.update_notification_settings(user, params) do
|
||||||
json(conn, %{status: "success"})
|
json(conn, %{status: "success"})
|
||||||
|
|
|
||||||
|
|
@ -37,4 +37,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiTagBuildingTest do
|
||||||
|
|
||||||
assert tag["id"] == url
|
assert tag["id"] == url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "local_url encodes question marks in filenames" do
|
||||||
|
url = Pleroma.Emoji.local_url("/emoji/file?name.png")
|
||||||
|
|
||||||
|
assert url == Pleroma.Web.Endpoint.url() <> "/emoji/file%3Fname.png"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,25 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||||
assert expected == AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
assert expected == AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "encodes emoji urls in the emojis field" do
|
||||||
|
user =
|
||||||
|
insert(:user,
|
||||||
|
name: ":brackets: :percent:",
|
||||||
|
emoji: %{
|
||||||
|
"brackets" => "/emoji/hana[pog].png",
|
||||||
|
"percent" => "/emoji/hana%20pog.png"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
%{emojis: emojis} =
|
||||||
|
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||||
|
|
||||||
|
emoji_urls = Map.new(emojis, &{&1.shortcode, &1.url})
|
||||||
|
|
||||||
|
assert emoji_urls["brackets"] == "/emoji/hana%5Bpog%5D.png"
|
||||||
|
assert emoji_urls["percent"] == "/emoji/hana%2520pog.png"
|
||||||
|
end
|
||||||
|
|
||||||
describe "roles and privileges" do
|
describe "roles and privileges" do
|
||||||
setup do
|
setup do
|
||||||
clear_config([:instance, :moderator_privileges], [:cofe, :only_moderator])
|
clear_config([:instance, :moderator_privileges], [:cofe, :only_moderator])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue