diff --git a/lib/pleroma/web/feed/feed_view.ex b/lib/pleroma/web/feed/feed_view.ex index 52771205e..cff8a72d1 100644 --- a/lib/pleroma/web/feed/feed_view.ex +++ b/lib/pleroma/web/feed/feed_view.ex @@ -112,4 +112,30 @@ def escape(html) do |> html_escape() |> safe_to_string() end + + # Encoding newlines, e.g., per XML spec + def rss_escape(nil), do: "" + def rss_escape(data) when is_binary(data) do + data + |> rss_escape_string() + |> to_string() + end + + defp rss_escape_string(""), do: "" + defp rss_escape_string(<<"&"::utf8, rest::binary>>), do: rss_escape_entity(rest) + defp rss_escape_string(<<"<"::utf8, rest::binary>>), do: ["<" | rss_escape_string(rest)] + defp rss_escape_string(<<">"::utf8, rest::binary>>), do: [">" | rss_escape_string(rest)] + defp rss_escape_string(<<"\""::utf8, rest::binary>>), do: [""" | rss_escape_string(rest)] + defp rss_escape_string(<<"'"::utf8, rest::binary>>), do: ["'" | rss_escape_string(rest)] + defp rss_escape_string(<<"\t"::utf8, rest::binary>>), do: [" " | rss_escape_string(rest)] + defp rss_escape_string(<<"\n"::utf8, rest::binary>>), do: [" " | rss_escape_string(rest)] + defp rss_escape_string(<<"\r\n"::utf8, rest::binary>>), do: [" " | rss_escape_string(rest)] + defp rss_escape_string(<<"\r"::utf8, rest::binary>>), do: [" " | rss_escape_string(rest)] + defp rss_escape_string(<>), do: [c | rss_escape_string(rest)] + defp rss_escape_entity(<<"amp;"::utf8, rest::binary>>), do: ["&" | rss_escape_string(rest)] + defp rss_escape_entity(<<"lt;"::utf8, rest::binary>>), do: ["<" | rss_escape_string(rest)] + defp rss_escape_entity(<<"gt;"::utf8, rest::binary>>), do: [">" | rss_escape_string(rest)] + defp rss_escape_entity(<<"quot;"::utf8, rest::binary>>), do: [""" | rss_escape_string(rest)] + defp rss_escape_entity(<<"apos;"::utf8, rest::binary>>), do: ["'" | rss_escape_string(rest)] + defp rss_escape_entity(rest), do: ["&" | rss_escape_string(rest)] end diff --git a/lib/pleroma/web/templates/feed/feed/_activity.rss.eex b/lib/pleroma/web/templates/feed/feed/_activity.rss.eex index 279f2171d..eca64d2db 100644 --- a/lib/pleroma/web/templates/feed/feed/_activity.rss.eex +++ b/lib/pleroma/web/templates/feed/feed/_activity.rss.eex @@ -14,6 +14,10 @@ <%= escape(@data["summary"]) %> <% end %> + <%= if get_in(@data, ["source", "mediaType"]) == "text/markdown" do %> + <%= rss_escape(get_in(@data, ["source", "content"])) %> + <% end %> + <%= if @activity.local do %> <%= @data["id"] %> <% else %>