Properly escape reserved URI charachters in upload urls
authorrinpatch <rinpatch@sdf.org>
Tue, 5 Mar 2019 15:09:23 +0000 (18:09 +0300)
committerrinpatch <rinpatch@sdf.org>
Tue, 5 Mar 2019 15:09:23 +0000 (18:09 +0300)
lib/pleroma/upload.ex

index 91a5db8c524f6e24b4b122c267cc5afd0a7c1a38..1a97e9fdee156354fdb26e78bab931a2474e32d9 100644 (file)
@@ -85,6 +85,10 @@ defmodule Pleroma.Upload do
     end
   end
 
+  def char_unescaped?(char) do
+    URI.char_unreserved?(char) or char == ?/
+  end
+
   defp get_opts(opts) do
     {size_limit, activity_type} =
       case Keyword.get(opts, :type) do
@@ -218,9 +222,7 @@ defmodule Pleroma.Upload do
   defp url_from_spec(base_url, {:file, path}) do
     path =
       path
-      |> URI.encode()
-      |> String.replace("?", "%3F")
-      |> String.replace(":", "%3A")
+      |> URI.encode(&char_unescaped?/1)
 
     [base_url, "media", path]
     |> Path.join()