try to always match the filename for proxy url
This commit is contained in:
parent
9e88ab2cad
commit
ccafecf9be
|
@ -35,10 +35,15 @@ def filename_matches(has_filename, path, url) do
|
||||||
|
|
||||||
path = URI.decode(path)
|
path = URI.decode(path)
|
||||||
|
|
||||||
if has_filename && filename && Path.basename(path) != filename do
|
if has_filename && filename && does_not_match(path, filename) do
|
||||||
{:wrong_filename, filename}
|
{:wrong_filename, filename}
|
||||||
else
|
else
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp does_not_match(path, filename) do
|
||||||
|
basename = Path.basename(path)
|
||||||
|
basename != filename and URI.decode(basename) != filename and URI.encode(basename) != filename
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -124,6 +124,17 @@ test "filename_matches matches non-url encoded paths" do
|
||||||
) == :ok
|
) == :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "encoded url are tried to match for proxy as `conn.request_path` encodes the url" do
|
||||||
|
# conn.request_path will return encoded url
|
||||||
|
request_path = "/ANALYSE-DAI-_-LE-STABLECOIN-100-D%C3%89CENTRALIS%C3%89-BQ.jpg"
|
||||||
|
|
||||||
|
assert MediaProxyController.filename_matches(
|
||||||
|
true,
|
||||||
|
request_path,
|
||||||
|
"https://mydomain.com/uploads/2019/07/ANALYSE-DAI-_-LE-STABLECOIN-100-DÉCENTRALISÉ-BQ.jpg"
|
||||||
|
) == :ok
|
||||||
|
end
|
||||||
|
|
||||||
test "uses the configured base_url" do
|
test "uses the configured base_url" do
|
||||||
base_url = Pleroma.Config.get([:media_proxy, :base_url])
|
base_url = Pleroma.Config.get([:media_proxy, :base_url])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue