diff options
Diffstat (limited to 'lib/pleroma')
| -rw-r--r-- | lib/pleroma/formatter.ex | 11 | ||||
| -rw-r--r-- | lib/pleroma/web/common_api/common_api.ex | 2 | ||||
| -rw-r--r-- | lib/pleroma/web/common_api/utils.ex | 12 | ||||
| -rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 1 | 
4 files changed, 20 insertions, 6 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/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index dc94e5377..d3a9f7b85 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -56,7 +56,7 @@ defmodule Pleroma.Web.CommonAPI do           inReplyTo <- get_replied_to_activity(data["in_reply_to_status_id"]),           to <- to_for_user_and_mentions(user, mentions, inReplyTo),           tags <- Formatter.parse_tags(status, data), -         content_html <- make_content_html(status, mentions, attachments, tags), +         content_html <- make_content_html(status, mentions, attachments, tags, data["no_attachment_links"]),           context <- make_context(inReplyTo),           cw <- data["spoiler_text"],           object <- make_note_data(user.ap_id, to, context, content_html, attachments, inReplyTo, tags, cw), diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 1a23b1ad2..e60dff7dc 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -38,15 +38,19 @@ defmodule Pleroma.Web.CommonAPI.Utils do      end    end -  def make_content_html(status, mentions, attachments, tags) do +  def make_content_html(status, mentions, attachments, tags, no_attachment_links \\ false) do      status      |> format_input(mentions, tags) -    |> add_attachments(attachments) +    |> maybe_add_attachments(attachments, no_attachment_links)    end    def make_context(%Activity{data: %{"context" => context}}), do: context    def make_context(_), do: Utils.generate_context_id +  def maybe_add_attachments(text, attachments, _no_links = true), do: text +  def maybe_add_attachments(text, attachments, _no_links) do +    add_attachments(text, attachments) +  end    def add_attachments(text, attachments) do      attachment_text = Enum.map(attachments, fn        (%{"url" => [%{"href" => href} | _]}) -> @@ -58,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/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 61bf8b4b8..e50f53ba4 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -212,6 +212,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do    def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do      params = params      |> Map.put("in_reply_to_status_id", params["in_reply_to_id"]) +    |> Map.put("no_attachment_links", true)      {:ok, activity} = CommonAPI.post(user, params)      render conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity} | 
