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
This commit is contained in:
parent
07064f73bc
commit
bb4ced0eb5
@ -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?\/?>/, " ")
|
||||
|> String.replace(~r/<br\s?\/?>/, " ")
|
||||
|> HTML.strip_tags()
|
||||
|> HtmlEntities.decode()
|
||||
|> Formatter.truncate(max_length)
|
||||
end
|
||||
|
||||
|
@ -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 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 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!</p>") ==
|
||||
"my title and a paragraph!"
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user