commit: 99a1c0890a5aee2a8051791b39b599d8e930dcbc
parent 80db6f1328212a0b00e26f548f02aa5d6a3c1715
Author: Phantasm <phantasm@centrum.cz>
Date: Fri, 29 Aug 2025 20:53:16 +0200
URI.encode_query needs an enum, add test for this case
Diffstat:
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex
@@ -241,7 +241,8 @@ defmodule Pleroma.Upload do
path =
HTTP.encode_url(path, encode_opts) <>
if Pleroma.Config.get([__MODULE__, :link_name], false) do
- "?name=#{URI.encode_query(name)}"
+ enum = %{name: name}
+ "?#{URI.encode_query(enum)}"
else
""
end
diff --git a/test/pleroma/upload_test.exs b/test/pleroma/upload_test.exs
@@ -282,4 +282,23 @@ defmodule Pleroma.UploadTest do
refute String.starts_with?(url, base_url <> "/media/")
end
end
+
+ describe "Setting a link_name for uploaded media" do
+ setup do: clear_config([Pleroma.Upload, :link_name], true)
+
+ test "encodes name parameter in query" do
+ File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
+
+ file = %Plug.Upload{
+ content_type: "image/jpeg",
+ path: Path.absname("test/fixtures/image_tmp.jpg"),
+ filename: "test file.jpg"
+ }
+
+ {:ok, data} = Upload.store(file)
+ [attachment_url | _] = data["url"]
+
+ assert Path.basename(attachment_url["href"]) == "test%20file.jpg?name=test+file.jpg"
+ end
+ end
end