logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/
commit: cfd2c08ef6f090a669dbb646b12d554f816b4c35
parent a0f73d0e2f1afca990f6f1f2b39c986acdee8408
Author: Phantasm <phantasm@centrum.cz>
Date:   Fri, 10 Oct 2025 22:37:16 +0200

lint

Diffstat:

Mlib/pleroma/http.ex33+++++++++++++++++++--------------
Mtest/pleroma/http_test.exs35++++++++++++++++++++++++++---------
Mtest/pleroma/web/activity_pub/mrf/media_proxy_warming_policy_test.exs10+++++-----
3 files changed, 50 insertions(+), 28 deletions(-)

diff --git a/lib/pleroma/http.ex b/lib/pleroma/http.ex @@ -146,8 +146,10 @@ defmodule Pleroma.HTTP do true -> URI.parse(url) |> then(fn parsed -> - path = encode_path(parsed.path, bypass_decode) - |> maybe_apply_path_encoding_quirks() + path = + encode_path(parsed.path, bypass_decode) + |> maybe_apply_path_encoding_quirks() + query = encode_query(parsed.query) %{parsed | path: path, query: query} @@ -197,7 +199,7 @@ defmodule Pleroma.HTTP do |> Enum.to_list() |> do_encode_query() end - + defp maybe_apply_path_encoding_quirks(path), do: path # Always uses www_form encoding @@ -221,19 +223,22 @@ defmodule Pleroma.HTTP do # URI.encode_query/2 does not appear to follow spec and encodes all parts of our URI path Constant. # This appears to work outside of edge-cases like The Guardian Rich Media Cards, # keeping behavior same as with URI.encode_query/2 unless otherwise specified via rules. - URI.encode_www_form(Kernel.to_string(key)) <> "=" <> - URI.encode(value, fn byte -> - URI.char_unreserved?(byte) || - Enum.any?( - rules, - fn char -> - char == byte - end) - end) - |> String.replace("%20", "+") + (URI.encode_www_form(Kernel.to_string(key)) <> + "=" <> + URI.encode(value, fn byte -> + URI.char_unreserved?(byte) || + Enum.any?( + rules, + fn char -> + char == byte + end + ) + end)) + |> String.replace("%20", "+") true -> - URI.encode_www_form(Kernel.to_string(key)) <> "=" <> URI.encode_www_form(Kernel.to_string(value)) + URI.encode_www_form(Kernel.to_string(key)) <> + "=" <> URI.encode_www_form(Kernel.to_string(value)) end end end diff --git a/test/pleroma/http_test.exs b/test/pleroma/http_test.exs @@ -38,13 +38,25 @@ defmodule Pleroma.HTTPTest do %{method: :get, url: "https://example.com/media/unicode%20%F0%9F%99%82%20.gif"} -> %Tesla.Env{status: 200, body: "unicode data"} - %{method: :get, url: "https://i.guim.co.uk/img/media/1069ef13c447908272c4de94174cec2b6352cb2f/0_91_2000_1201/master/2000.jpg?width=1200&height=630&quality=85&auto=format&fit=crop&precrop=40:21,offset-x50,offset-y0&overlay-align=bottom%2Cleft&overlay-width=100p&overlay-base64=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctb3BpbmlvbnMtYWdlLTIwMTkucG5n&enable=upscale&s=cba21427a73512fdc9863c486c03fdd8"} -> + %{ + method: :get, + url: + "https://i.guim.co.uk/img/media/1069ef13c447908272c4de94174cec2b6352cb2f/0_91_2000_1201/master/2000.jpg?width=1200&height=630&quality=85&auto=format&fit=crop&precrop=40:21,offset-x50,offset-y0&overlay-align=bottom%2Cleft&overlay-width=100p&overlay-base64=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctb3BpbmlvbnMtYWdlLTIwMTkucG5n&enable=upscale&s=cba21427a73512fdc9863c486c03fdd8" + } -> %Tesla.Env{status: 200, body: "Guardian image quirk"} - %{method: :get, url: "https://example.com/emoji/Pack%201/koronebless.png?precrop=40:21,overlay-x0,overlay-y0&foo=bar+baz"} -> + %{ + method: :get, + url: + "https://example.com/emoji/Pack%201/koronebless.png?precrop=40:21,overlay-x0,overlay-y0&foo=bar+baz" + } -> %Tesla.Env{status: 200, body: "Space in query with Guardian quirk"} - %{method: :get, url: "https://examplebucket.s3.amazonaws.com/test.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=accessKEY%2F20130721%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20130721T201207Z&X-Amz-Expires=86400&X-Amz-Signature=SIGNATURE&X-Amz-SignedHeaders=host"} -> + %{ + method: :get, + url: + "https://examplebucket.s3.amazonaws.com/test.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=accessKEY%2F20130721%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20130721T201207Z&X-Amz-Expires=86400&X-Amz-Signature=SIGNATURE&X-Amz-SignedHeaders=host" + } -> %Tesla.Env{status: 200, body: "AWS S3 data"} end) @@ -140,7 +152,8 @@ defmodule Pleroma.HTTPTest do test "properly applies Guardian image query quirk" do clear_config(:test_url_encoding, true) - url = "https://i.guim.co.uk/img/media/1069ef13c447908272c4de94174cec2b6352cb2f/0_91_2000_1201/master/2000.jpg?width=1200&height=630&quality=85&auto=format&fit=crop&precrop=40:21,offset-x50,offset-y0&overlay-align=bottom%2Cleft&overlay-width=100p&overlay-base64=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctb3BpbmlvbnMtYWdlLTIwMTkucG5n&enable=upscale&s=cba21427a73512fdc9863c486c03fdd8" + url = + "https://i.guim.co.uk/img/media/1069ef13c447908272c4de94174cec2b6352cb2f/0_91_2000_1201/master/2000.jpg?width=1200&height=630&quality=85&auto=format&fit=crop&precrop=40:21,offset-x50,offset-y0&overlay-align=bottom%2Cleft&overlay-width=100p&overlay-base64=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctb3BpbmlvbnMtYWdlLTIwMTkucG5n&enable=upscale&s=cba21427a73512fdc9863c486c03fdd8" result = HTTP.encode_url(url) @@ -154,9 +167,11 @@ defmodule Pleroma.HTTPTest do test "properly encodes spaces as \"pluses\" in query when using quirks" do clear_config(:test_url_encoding, true) - url = "https://example.com/emoji/Pack 1/koronebless.png?precrop=40:21,overlay-x0,overlay-y0&foo=bar baz" + url = + "https://example.com/emoji/Pack 1/koronebless.png?precrop=40:21,overlay-x0,overlay-y0&foo=bar baz" - properly_encoded_url = "https://example.com/emoji/Pack%201/koronebless.png?precrop=40:21,overlay-x0,overlay-y0&foo=bar+baz" + properly_encoded_url = + "https://example.com/emoji/Pack%201/koronebless.png?precrop=40:21,overlay-x0,overlay-y0&foo=bar+baz" result = HTTP.encode_url(url) @@ -170,8 +185,11 @@ defmodule Pleroma.HTTPTest do test "properly encode AWS S3 queries" do clear_config(:test_url_encoding, true) - url = "https://examplebucket.s3.amazonaws.com/test.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=accessKEY%2F20130721%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20130721T201207Z&X-Amz-Expires=86400&X-Amz-Signature=SIGNATURE&X-Amz-SignedHeaders=host" - unencoded_url = "https://examplebucket.s3.amazonaws.com/test.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=accessKEY/20130721/us-east-1/s3/aws4_request&X-Amz-Date=20130721T201207Z&X-Amz-Expires=86400&X-Amz-Signature=SIGNATURE&X-Amz-SignedHeaders=host" + url = + "https://examplebucket.s3.amazonaws.com/test.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=accessKEY%2F20130721%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20130721T201207Z&X-Amz-Expires=86400&X-Amz-Signature=SIGNATURE&X-Amz-SignedHeaders=host" + + unencoded_url = + "https://examplebucket.s3.amazonaws.com/test.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=accessKEY/20130721/us-east-1/s3/aws4_request&X-Amz-Date=20130721T201207Z&X-Amz-Expires=86400&X-Amz-Signature=SIGNATURE&X-Amz-SignedHeaders=host" result = HTTP.encode_url(url) result_unencoded = HTTP.encode_url(unencoded_url) @@ -182,7 +200,6 @@ defmodule Pleroma.HTTPTest do {:ok, result_get} = HTTP.get(result) assert result_get.status == 200 - end test "preserves query key order" do diff --git a/test/pleroma/web/activity_pub/mrf/media_proxy_warming_policy_test.exs b/test/pleroma/web/activity_pub/mrf/media_proxy_warming_policy_test.exs @@ -62,9 +62,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do get: fn _, _, _ -> {:ok, []} end, encode_url: fn url -> :meck.passthrough([url]) end, encode_url: fn url, opts -> :meck.passthrough([url, opts]) end do - MediaProxyWarmingPolicy.filter(@message) + MediaProxyWarmingPolicy.filter(@message) - assert called(HTTP.get(:_, :_, :_)) + assert called(HTTP.get(:_, :_, :_)) end end @@ -92,9 +92,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do get: fn _, _, _ -> {:ok, []} end, encode_url: fn url -> :meck.passthrough([url]) end, encode_url: fn url, opts -> :meck.passthrough([url, opts]) end do - MRF.filter_one(MediaProxyWarmingPolicy, @message_with_history) + MRF.filter_one(MediaProxyWarmingPolicy, @message_with_history) - assert called(HTTP.get(:_, :_, :_)) + assert called(HTTP.get(:_, :_, :_)) end end @@ -107,7 +107,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do get: fn _, _, _ -> {:ok, []} end, encode_url: fn url -> :meck.passthrough([url]) end, encode_url: fn url, opts -> :meck.passthrough([url, opts]) end do - MRF.filter_one(MediaProxyWarmingPolicy, @message_with_history |> Map.put("type", "Update")) + MRF.filter_one(MediaProxyWarmingPolicy, @message_with_history |> Map.put("type", "Update")) assert called(HTTP.get(:_, :_, :_)) end