projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
html: allow scrubbing policies to be stackable
[akkoma]
/
lib
/
pleroma
/
formatter.ex
diff --git
a/lib/pleroma/formatter.ex
b/lib/pleroma/formatter.ex
index e15c08fd6d69dacd264c6da60408660ac5918ae1..62f54a3f255e2e74d5e7c6dc7dfa7ff1f83d4e46 100644
(file)
--- a/
lib/pleroma/formatter.ex
+++ b/
lib/pleroma/formatter.ex
@@
-1,6
+1,7
@@
defmodule Pleroma.Formatter do
alias Pleroma.User
alias Pleroma.Web.MediaProxy
defmodule Pleroma.Formatter do
alias Pleroma.User
alias Pleroma.Web.MediaProxy
+ alias Pleroma.HTML
@tag_regex ~r/\#\w+/u
def parse_tags(text, data \\ %{}) do
@tag_regex ~r/\#\w+/u
def parse_tags(text, data \\ %{}) do
@@
-16,7
+17,7
@@
defmodule Pleroma.Formatter do
def parse_mentions(text) do
# Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
regex =
def parse_mentions(text) do
# Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
regex =
- ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]
+
@?[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u
+ ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]
*
@?[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u
Regex.scan(regex, text)
|> List.flatten()
Regex.scan(regex, text)
|> List.flatten()
@@
-144,8
+145,8
@@
defmodule Pleroma.Formatter do
def emojify(text, emoji) do
Enum.reduce(emoji, text, fn {emoji, file}, text ->
def emojify(text, emoji) do
Enum.reduce(emoji, text, fn {emoji, file}, text ->
- emoji = H
tmlSanitizeEx
.strip_tags(emoji)
- file = H
tmlSanitizeEx
.strip_tags(file)
+ emoji = H
TML
.strip_tags(emoji)
+ file = H
TML
.strip_tags(file)
String.replace(
text,
String.replace(
text,
@@
-154,13
+155,16
@@
defmodule Pleroma.Formatter do
MediaProxy.url(file)
}' />"
)
MediaProxy.url(file)
}' />"
)
+ |> HTML.filter_tags()
end)
end
end)
end
- def get_emoji(text) do
+ def get_emoji(text)
when is_binary(text)
do
Enum.filter(@emoji, fn {emoji, _} -> String.contains?(text, ":#{emoji}:") end)
end
Enum.filter(@emoji, fn {emoji, _} -> String.contains?(text, ":#{emoji}:") end)
end
+ def get_emoji(_), do: []
+
def get_custom_emoji() do
@emoji
end
def get_custom_emoji() do
@emoji
end
@@
-272,8
+276,8
@@
defmodule Pleroma.Formatter do
subs =
subs ++
subs =
subs ++
- Enum.map(tags, fn {
_
, tag, uuid} ->
- url = "<a href='#{Pleroma.Web.base_url()}/tag/#{tag}' rel='tag'>#
#{tag
}</a>"
+ Enum.map(tags, fn {
tag_text
, tag, uuid} ->
+ url = "<a href='#{Pleroma.Web.base_url()}/tag/#{tag}' rel='tag'>#
{tag_text
}</a>"
{uuid, url}
end)
{uuid, url}
end)