From bf91e5659ffd03b15110b6f1094b30aed940e45b Mon Sep 17 00:00:00 2001 From: eal Date: Thu, 7 Dec 2017 21:34:25 +0200 Subject: [PATCH] Fix HTML escape breaking some links. --- lib/pleroma/formatter.ex | 9 +++++++++ lib/pleroma/web/common_api/utils.ex | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index fbcbca979..275c60f32 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -24,6 +24,15 @@ def parse_mentions(text) 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 1a23b1ad2..f46db4cf0 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -58,8 +58,8 @@ def add_attachments(text, attachments) 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", "
") |> add_user_links(mentions)