diff options
author | raeno <just.raeno@gmail.com> | 2018-12-14 21:07:06 +0100 |
---|---|---|
committer | raeno <just.raeno@gmail.com> | 2018-12-14 21:07:06 +0100 |
commit | b0c3211984c0aa807ea58897308f04ad42651cf1 (patch) | |
tree | c058e2273a003e834d8c84fd0d8cea6f4ad1c9b4 /lib | |
parent | 90b00701ff0e2622825ef4c86409a27691763baf (diff) | |
download | pleroma-b0c3211984c0aa807ea58897308f04ad42651cf1.tar.gz |
Scrub html from activity.content or user.bio for opengraph meta
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/ostatus/metadata.ex | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/pleroma/web/ostatus/metadata.ex b/lib/pleroma/web/ostatus/metadata.ex index 120a89a8b..9935726fc 100644 --- a/lib/pleroma/web/ostatus/metadata.ex +++ b/lib/pleroma/web/ostatus/metadata.ex @@ -16,7 +16,7 @@ defmodule Pleroma.Web.Metadata do # opengraph for single status defp opengraph_tags(%{activity: activity, user: user}) do - with truncated_content = Formatter.truncate(activity.data["object"]["content"]) do + with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do [ {:meta, [ @@ -35,7 +35,7 @@ defmodule Pleroma.Web.Metadata do # opengraph for user card defp opengraph_tags(%{user: user}) do - with truncated_bio = Formatter.truncate(user.bio) do + with truncated_bio = scrub_html_and_truncate(user.bio) do [ {:meta, [ @@ -64,6 +64,14 @@ defmodule Pleroma.Web.Metadata do end end + defp scrub_html_and_truncate(content) do + content + # html content comes from DB already encoded, decode first and scrub after + |> HtmlEntities.decode() + |> Pleroma.HTML.strip_tags() + |> Formatter.truncate() + end + defp user_avatar_url(user) do User.avatar_url(user) |> MediaProxy.url() end |