Commit b6567c9f authored by kaniini's avatar kaniini

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

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

See merge request !1403
parents db75288b 6a6c4d13
Pipeline #14586 passed with stages
in 43 minutes and 37 seconds
...@@ -28,12 +28,7 @@ def remote(conn, %{"sig" => sig64, "url" => url64} = params) do ...@@ -28,12 +28,7 @@ def remote(conn, %{"sig" => sig64, "url" => url64} = params) do
end end
def filename_matches(has_filename, path, url) do def filename_matches(has_filename, path, url) do
filename = filename = url |> MediaProxy.filename()
url
|> MediaProxy.filename()
|> URI.decode()
path = URI.decode(path)
if has_filename && filename && Path.basename(path) != filename do if has_filename && filename && Path.basename(path) != filename do
{:wrong_filename, filename} {:wrong_filename, filename}
......
...@@ -88,10 +88,10 @@ test "validates signature" do ...@@ -88,10 +88,10 @@ test "validates signature" do
assert decode_url(sig, base64) == {:error, :invalid_signature} assert decode_url(sig, base64) == {:error, :invalid_signature}
end end
test "filename_matches matches url encoded paths" do test "filename_matches preserves the encoded or decoded path" do
assert MediaProxyController.filename_matches( assert MediaProxyController.filename_matches(
true, true,
"/Hello%20world.jpg", "/Hello world.jpg",
"http://pleroma.social/Hello world.jpg" "http://pleroma.social/Hello world.jpg"
) == :ok ) == :ok
...@@ -100,19 +100,11 @@ test "filename_matches matches url encoded paths" do ...@@ -100,19 +100,11 @@ test "filename_matches matches url encoded paths" do
"/Hello%20world.jpg", "/Hello%20world.jpg",
"http://pleroma.social/Hello%20world.jpg" "http://pleroma.social/Hello%20world.jpg"
) == :ok ) == :ok
end
test "filename_matches matches non-url encoded paths" do
assert MediaProxyController.filename_matches( assert MediaProxyController.filename_matches(
true, true,
"/Hello world.jpg", "/my%2Flong%2Furl%2F2019%2F07%2FS.jpg",
"http://pleroma.social/Hello%20world.jpg" "http://pleroma.social/my%2Flong%2Furl%2F2019%2F07%2FS.jpg"
) == :ok
assert MediaProxyController.filename_matches(
true,
"/Hello world.jpg",
"http://pleroma.social/Hello world.jpg"
) == :ok ) == :ok
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment