aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/pleroma/formatter.ex11
-rw-r--r--lib/pleroma/web/common_api/utils.ex4
-rw-r--r--test/formatter_test.exs10
3 files changed, 22 insertions, 3 deletions
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index fbcbca979..c98db2d94 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -1,7 +1,7 @@
defmodule Pleroma.Formatter do
alias Pleroma.User
- @link_regex ~r/https?:\/\/[\w\.\/?=\-#%&@~]+[\w\/]/u
+ @link_regex ~r/https?:\/\/[\w\.\/?=\-#%&@~\(\)]+[\w\/]/u
def linkify(text) do
Regex.replace(@link_regex, text, "<a href='\\0'>\\0</a>")
end
@@ -24,6 +24,15 @@ defmodule Pleroma.Formatter do
|> Enum.filter(fn ({_match, user}) -> user end)
end
+ def html_escape(text) do
+ Regex.split(@link_regex, text, include_captures: true)
+ |> Enum.map_every(2, fn chunk ->
+ {:safe, part} = Phoenix.HTML.html_escape(chunk)
+ part
+ end)
+ |> Enum.join("")
+ end
+
@finmoji [
"a_trusted_friend",
"alandislands",
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 2d9fdaf6c..e60dff7dc 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -62,8 +62,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do
end
def format_input(text, mentions, _tags) do
- Phoenix.HTML.html_escape(text)
- |> elem(1)
+ text
+ |> Formatter.html_escape
|> Formatter.linkify
|> String.replace("\n", "<br>")
|> add_user_links(mentions)
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index f91973881..cb7695e8e 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -25,6 +25,16 @@ defmodule Pleroma.FormatterTest do
expected = "<a href='http://www.cs.vu.nl/~ast/intel/'>http://www.cs.vu.nl/~ast/intel/</a>"
assert Formatter.linkify(text) == expected
+
+ text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087"
+ expected = "<a href='https://forum.zdoom.org/viewtopic.php?f=44&t=57087'>https://forum.zdoom.org/viewtopic.php?f=44&t=57087</a>"
+
+ assert Formatter.linkify(text) == expected
+
+ text = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul"
+ expected = "<a href='https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul'>https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul</a>"
+
+ assert Formatter.linkify(text) == expected
end
end