mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 06:09:15 +08:00
FIX: FileHelper
should prioritize response content-type.
Request to a URL with `.png` extension may return a jpg instead causing us to attach the wrong extension to an upload.
This commit is contained in:
@ -12,7 +12,6 @@ describe FileHelper do
|
||||
end
|
||||
|
||||
describe "download" do
|
||||
|
||||
it "correctly raises an OpenURI HTTP error if it gets a 404 even with redirect" do
|
||||
url = "http://fourohfour.com/404"
|
||||
stub_request(:get, url).to_return(status: 404, body: "404")
|
||||
@ -69,6 +68,24 @@ describe FileHelper do
|
||||
)
|
||||
expect(tmpfile.read[0..5]).to eq("GIF89a")
|
||||
end
|
||||
|
||||
describe 'when url is a jpeg' do
|
||||
let(:url) { "https://eviltrout.com/trout.jpg" }
|
||||
|
||||
it "should prioritize the content type returned by the response" do
|
||||
stub_request(:get, url).to_return(body: png, headers: {
|
||||
"content-type": "image/png"
|
||||
})
|
||||
|
||||
tmpfile = FileHelper.download(
|
||||
url,
|
||||
max_file_size: 10000,
|
||||
tmp_file_name: 'trouttmp'
|
||||
)
|
||||
|
||||
expect(File.extname(tmpfile)).to eq('.png')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user