aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Felder <feld@feld.me>2021-06-11 15:58:55 -0500
committerMark Felder <feld@feld.me>2021-06-11 15:58:55 -0500
commitbb4ced0eb5cdf8744adea2da9c268734a6170060 (patch)
treec05734b53320bcd6f8953ab14c3af288900aa47c
parent07064f73bcf9091774a72650a5cc9cb973810bd2 (diff)
downloadpleroma-bb4ced0eb5cdf8744adea2da9c268734a6170060.tar.gz
scrub_html_and_truncate/1 -> filter_html_and_truncate/1
They shouldn't share the same name when /1 was used for a different type of incoming data anyway
-rw-r--r--lib/pleroma/web/metadata/utils.ex7
-rw-r--r--test/pleroma/web/metadata/utils_test.exs26
2 files changed, 15 insertions, 18 deletions
diff --git a/lib/pleroma/web/metadata/utils.ex b/lib/pleroma/web/metadata/utils.ex
index 649319db5..f5b79a82c 100644
--- a/lib/pleroma/web/metadata/utils.ex
+++ b/lib/pleroma/web/metadata/utils.ex
@@ -7,7 +7,7 @@ defmodule Pleroma.Web.Metadata.Utils do
alias Pleroma.Formatter
alias Pleroma.HTML
- def scrub_html_and_truncate(%{data: %{"content" => content}} = _object) do
+ def filter_html_and_truncate(%{data: %{"content" => content}} = _object) do
content
# html content comes from DB already encoded, decode first and scrub after
|> Emoji.Formatter.demojify()
@@ -20,9 +20,10 @@ defmodule Pleroma.Web.Metadata.Utils do
def scrub_html_and_truncate(content, max_length \\ 200) when is_binary(content) do
content
|> Emoji.Formatter.demojify()
- |> HTML.filter_tags(Pleroma.HTML.Scrubber.BreaksOnly)
|> HtmlEntities.decode()
- |> String.replace(~r/<br\s?\/?>/, "&#10;&#13;")
+ |> String.replace(~r/<br\s?\/?>/, " ")
+ |> HTML.strip_tags()
+ |> HtmlEntities.decode()
|> Formatter.truncate(max_length)
end
diff --git a/test/pleroma/web/metadata/utils_test.exs b/test/pleroma/web/metadata/utils_test.exs
index c5d241886..9d94bf9ca 100644
--- a/test/pleroma/web/metadata/utils_test.exs
+++ b/test/pleroma/web/metadata/utils_test.exs
@@ -7,8 +7,8 @@ defmodule Pleroma.Web.Metadata.UtilsTest do
import Pleroma.Factory
alias Pleroma.Web.Metadata.Utils
- describe "scrub_html_and_truncate" do
- test "it returns text without encode HTML (objects)" do
+ describe "filter_html_and_truncate/1" do
+ test "it returns text without HTML" do
user = insert(:user)
note =
@@ -20,10 +20,10 @@ defmodule Pleroma.Web.Metadata.UtilsTest do
}
})
- assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
+ assert Utils.filter_html_and_truncate(note) == "Pleroma's really cool!"
end
- test "it replaces <br> with compatible HTML entity (objects)" do
+ test "it replaces <br> with compatible HTML entity (meta tags, push notifications)" do
user = insert(:user)
note =
@@ -35,31 +35,27 @@ defmodule Pleroma.Web.Metadata.UtilsTest do
}
})
- assert Utils.scrub_html_and_truncate(note) ==
+ assert Utils.filter_html_and_truncate(note) ==
"First line&#10;&#13;Second line"
end
+ end
- test "it returns text without encode HTML (binaries)" do
+ describe "scrub_html_and_truncate/2" do
+ test "it returns text without encode HTML" do
assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!"
end
- test "it truncates to specified chars (binaries)" do
+ test "it truncates to specified chars" do
assert Utils.scrub_html_and_truncate("Pleroma's really cool!", 10) == "Pleroma..."
end
- # push notifications and link previews should be able to display newlines
- test "it replaces <br> with compatible HTML entity (binaries)" do
- assert Utils.scrub_html_and_truncate("First line<br>Second line") ==
- "First line&#10;&#13;Second line"
- end
-
- test "it strips emojis (binaries)" do
+ test "it strips emojis" do
assert Utils.scrub_html_and_truncate(
"Open the door get on the floor everybody walk the dinosaur :dinosaur:"
) == "Open the door get on the floor everybody walk the dinosaur"
end
- test "it strips HTML tags and other entities (binaries)" do
+ test "it strips HTML tags and other entities" do
assert Utils.scrub_html_and_truncate("<title>my title</title> <p>and a paragraph&#33;</p>") ==
"my title and a paragraph!"
end