Merge pull request 'translations' (#133) from translations into develop
authorfloatingghost <hannah@coffee-and-dreams.uk>
Mon, 1 Aug 2022 12:48:26 +0000 (12:48 +0000)
committerfloatingghost <hannah@coffee-and-dreams.uk>
Mon, 1 Aug 2022 12:48:26 +0000 (12:48 +0000)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/133

lib/mix/tasks/pleroma/user.ex
lib/pleroma/formatter.ex
lib/pleroma/web/common_api/utils.ex
lib/pleroma/web/media_proxy/media_proxy_controller.ex
priv/scrubbers/default.ex
test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
test/pleroma/web/media_proxy/media_proxy_controller_test.exs

index 8972d4cfb927d60ac2aa51e0a98493571e310cfa..d2d41665521744d11bcc212bcea243e32a2f1508 100644 (file)
@@ -496,12 +496,12 @@ defmodule Mix.Tasks.Pleroma.User do
            {:follow_data, Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(local, remote)} do
       calculated_state = User.following?(local, remote)
 
-      shell_info(
+      IO.puts(
         "Request state is #{request_state}, vs calculated state of following=#{calculated_state}"
       )
 
       if calculated_state == false && request_state == "accept" do
-        shell_info("Discrepancy found, fixing")
+        IO.puts("Discrepancy found, fixing")
         Pleroma.Web.CommonAPI.reject_follow_request(local, remote)
         shell_info("Relationship fixed")
       else
index ad29d21d77d464622c2bf73b0cf775b5d83accab..575bf9b2dcb20d3bc0ded04ea0abdb406cb6d0f1 100644 (file)
@@ -136,7 +136,12 @@ defmodule Pleroma.Formatter do
     HTML.filter_tags(text)
   end
 
-  def html_escape(text, format) when format in ["text/plain", "text/x.misskeymarkdown"] do
+  def html_escape(text, "text/x.misskeymarkdown") do
+    text
+    |> HTML.filter_tags()
+  end
+
+  def html_escape(text, "text/plain") do
     Regex.split(@link_regex, text, include_captures: true)
     |> Enum.map_every(2, fn chunk ->
       {:safe, part} = Phoenix.HTML.html_escape(chunk)
index f5bc3acf553a23ff178934da486c448500eb82a5..826160a23c0c3783ceffaaf184aab8a9380e98f2 100644 (file)
@@ -259,8 +259,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
   @doc """
   Formatting text to plain text, BBCode, HTML, or Markdown
   """
-  def format_input(text, format, options)
-      when format in ["text/plain", "text/x.misskeymarkdown"] do
+  def format_input(text, "text/plain", options) do
     text
     |> Formatter.html_escape("text/plain")
     |> Formatter.linkify(options)
@@ -284,6 +283,15 @@ defmodule Pleroma.Web.CommonAPI.Utils do
     |> Formatter.linkify(options)
   end
 
+  def format_input(text, "text/x.misskeymarkdown", options) do
+    text
+    |> Formatter.linkify(options)
+    |> Formatter.html_escape("text/x.misskeymarkdown")
+    |> (fn {text, mentions, tags} ->
+          {String.replace(text, ~r/\r?\n/, "<br>"), mentions, tags}
+        end).()
+  end
+
   def format_input(text, "text/markdown", options) do
     text
     |> Formatter.mentions_escape(options)
index b3a92d75a9b157b0f33f11ad27ae90f6400fdbc8..84e07132a6d115f8b6c796a2f827f1883c3b8951 100644 (file)
@@ -54,7 +54,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
     media_proxy_url = MediaProxy.url(url)
 
     with {:ok, %{status: status} = head_response} when status in 200..299 <-
-           Pleroma.HTTP.request("head", media_proxy_url, [], [], name: MyFinch) do
+           Pleroma.HTTP.request("HEAD", media_proxy_url, [], [], name: MyFinch) do
       content_type = Tesla.get_header(head_response, "content-type")
       content_length = Tesla.get_header(head_response, "content-length")
       content_length = content_length && String.to_integer(content_length)
index 4694a92a53b657f501c6574f7e33fc0f20064daa..478cbde9bef47ad1d5ee06c196aebd7bc64afca2 100644 (file)
@@ -97,5 +97,8 @@ defmodule Pleroma.HTML.Scrubber.Default do
     Meta.allow_tag_with_these_attributes(:font, ["face"])
   end
 
+  Meta.allow_tag_with_these_attributes(:center, [])
+  Meta.allow_tag_with_these_attributes(:small, [])
+
   Meta.strip_everything_not_covered()
 end
index 8b39829168bbd06de32a45dab570aeb5ec0807d6..09cd1a964f55b694ff6dd4c784213284bab68a1d 100644 (file)
@@ -130,18 +130,21 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
         |> Jason.decode!()
 
       expected_content =
-        "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span> linkifylink <a class=\"hashtag\" data-tag=\"dancedance\" href=\"http://localhost:4001/tag/dancedance\" rel=\"tag ugc\">#dancedance</a> $[jelly mfm goes here] <br><br>## aaa"
+        "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span> linkifylink <a class=\"hashtag\" data-tag=\"dancedance\" href=\"http://localhost:4001/tag/dancedance\">#dancedance</a> $[jelly mfm goes here] <br><br>## aaa"
+
+      changes = ArticleNotePageValidator.cast_and_validate(note)
 
       %{
         valid?: true,
         changes: %{
-          content: ^expected_content,
           source: %{
             "content" => "@akkoma_user linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
             "mediaType" => "text/x.misskeymarkdown"
           }
         }
-      } = ArticleNotePageValidator.cast_and_validate(note)
+      } = changes
+
+      assert changes.changes[:content] == expected_content
     end
   end
 end
index 1f2e5419446fba81c870b5e9af7b8f9fd4aaeca7..e4b66c109637167ebfa46cf7332b4c4eef37f9e3 100644 (file)
@@ -158,7 +158,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
       media_proxy_url: media_proxy_url
     } do
       Tesla.Mock.mock(fn
-        %{method: "head", url: ^media_proxy_url} ->
+        %{method: "HEAD", url: ^media_proxy_url} ->
           %Tesla.Env{status: 500, body: ""}
       end)
 
@@ -173,7 +173,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
       media_proxy_url: media_proxy_url
     } do
       Tesla.Mock.mock(fn
-        %{method: "head", url: ^media_proxy_url} ->
+        %{method: "HEAD", url: ^media_proxy_url} ->
           %Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/pdf"}]}
       end)
 
@@ -193,7 +193,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
       clear_config([:media_preview_proxy, :min_content_length], 1_000_000_000)
 
       Tesla.Mock.mock(fn
-        %{method: "head", url: ^media_proxy_url} ->
+        %{method: "HEAD", url: ^media_proxy_url} ->
           %Tesla.Env{
             status: 200,
             body: "",
@@ -218,7 +218,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
            media_proxy_url: media_proxy_url
          } do
       Tesla.Mock.mock(fn
-        %{method: "head", url: ^media_proxy_url} ->
+        %{method: "HEAD", url: ^media_proxy_url} ->
           %Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/gif"}]}
       end)
 
@@ -236,7 +236,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
            media_proxy_url: media_proxy_url
          } do
       Tesla.Mock.mock(fn
-        %{method: "head", url: ^media_proxy_url} ->
+        %{method: "HEAD", url: ^media_proxy_url} ->
           %Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
       end)
 
@@ -256,7 +256,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
       clear_config([:media_preview_proxy, :min_content_length], 100_000)
 
       Tesla.Mock.mock(fn
-        %{method: "head", url: ^media_proxy_url} ->
+        %{method: "HEAD", url: ^media_proxy_url} ->
           %Tesla.Env{
             status: 200,
             body: "",
@@ -278,7 +278,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
       assert_dependencies_installed()
 
       Tesla.Mock.mock(fn
-        %{method: "head", url: ^media_proxy_url} ->
+        %{method: "HEAD", url: ^media_proxy_url} ->
           %Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/png"}]}
 
         %{method: :get, url: ^media_proxy_url} ->
@@ -300,7 +300,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
       assert_dependencies_installed()
 
       Tesla.Mock.mock(fn
-        %{method: "head", url: ^media_proxy_url} ->
+        %{method: "HEAD", url: ^media_proxy_url} ->
           %Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
 
         %{method: :get, url: ^media_proxy_url} ->
@@ -320,7 +320,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
       media_proxy_url: media_proxy_url
     } do
       Tesla.Mock.mock(fn
-        %{method: "head", url: ^media_proxy_url} ->
+        %{method: "HEAD", url: ^media_proxy_url} ->
           %Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
 
         %{method: :get, url: ^media_proxy_url} ->