logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: b6567c9f4e290ba8ad928c9ed10e72d2589dd89a
parent: db75288b71e7531f8e5033f56fc0b9a7d1d8efb3
Author: kaniini <ariadne@dereferenced.org>
Date:   Fri, 12 Jul 2019 15:34:00 +0000

Merge branch 'url-parser-proxy' into 'develop'

preserve the original path/filename (no encoding/decoding) for proxy

See merge request pleroma/pleroma!1403

Diffstat:

Mlib/pleroma/web/media_proxy/controller.ex7+------
Mtest/media_proxy_test.exs16++++------------
2 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex @@ -28,12 +28,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do end def filename_matches(has_filename, path, url) do - filename = - url - |> MediaProxy.filename() - |> URI.decode() - - path = URI.decode(path) + filename = url |> MediaProxy.filename() if has_filename && filename && Path.basename(path) != filename do {:wrong_filename, filename} diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs @@ -88,10 +88,10 @@ defmodule Pleroma.MediaProxyTest do assert decode_url(sig, base64) == {:error, :invalid_signature} end - test "filename_matches matches url encoded paths" do + test "filename_matches preserves the encoded or decoded path" do assert MediaProxyController.filename_matches( true, - "/Hello%20world.jpg", + "/Hello world.jpg", "http://pleroma.social/Hello world.jpg" ) == :ok @@ -100,19 +100,11 @@ defmodule Pleroma.MediaProxyTest do "/Hello%20world.jpg", "http://pleroma.social/Hello%20world.jpg" ) == :ok - end - test "filename_matches matches non-url encoded paths" do assert MediaProxyController.filename_matches( true, - "/Hello world.jpg", - "http://pleroma.social/Hello%20world.jpg" - ) == :ok - - assert MediaProxyController.filename_matches( - true, - "/Hello world.jpg", - "http://pleroma.social/Hello world.jpg" + "/my%2Flong%2Furl%2F2019%2F07%2FS.jpg", + "http://pleroma.social/my%2Flong%2Furl%2F2019%2F07%2FS.jpg" ) == :ok end