diff --git a/lib/pleroma/web/metadata/utils.ex b/lib/pleroma/web/metadata/utils.ex index a519fbf01..649319db5 100644 --- a/lib/pleroma/web/metadata/utils.ex +++ b/lib/pleroma/web/metadata/utils.ex @@ -3,19 +3,17 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Utils do - alias Pleroma.Activity alias Pleroma.Emoji alias Pleroma.Formatter alias Pleroma.HTML - def scrub_html_and_truncate(%{data: %{"content" => content}} = object) do + def scrub_html_and_truncate(%{data: %{"content" => content}} = _object) do content # html content comes from DB already encoded, decode first and scrub after - |> HtmlEntities.decode() - |> String.replace(~r//, " ") - |> Activity.HTML.get_cached_stripped_html_for_activity(object, "metadata") |> Emoji.Formatter.demojify() + |> HTML.filter_tags(Pleroma.HTML.Scrubber.BreaksOnly) |> HtmlEntities.decode() + |> String.replace(~r//, " ") |> Formatter.truncate() end diff --git a/test/pleroma/web/metadata/utils_test.exs b/test/pleroma/web/metadata/utils_test.exs index b5d3e3566..c5d241886 100644 --- a/test/pleroma/web/metadata/utils_test.exs +++ b/test/pleroma/web/metadata/utils_test.exs @@ -23,6 +23,22 @@ defmodule Pleroma.Web.Metadata.UtilsTest do assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!" end + test "it replaces
with compatible HTML entity (objects)" do + user = insert(:user) + + note = + insert(:note, %{ + data: %{ + "actor" => user.ap_id, + "id" => "https://pleroma.gov/objects/whatever", + "content" => "First line
Second line" + } + }) + + assert Utils.scrub_html_and_truncate(note) == + "First line Second line" + end + test "it returns text without encode HTML (binaries)" do assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!" end @@ -44,7 +60,8 @@ defmodule Pleroma.Web.Metadata.UtilsTest do end test "it strips HTML tags and other entities (binaries)" do - assert Utils.scrub_html_and_truncate("my title

and a paragraph!

") == "my title and a paragraph!" + assert Utils.scrub_html_and_truncate("my title

and a paragraph!

") == + "my title and a paragraph!" end end end