mirror of
https://github.com/discourse/discourse.git
synced 2025-02-22 14:29:38 +08:00
FIX: don't 💥 with an invalid URI
This commit is contained in:
parent
9457b03da1
commit
8d48779b5c
@ -232,9 +232,8 @@ class Upload < ActiveRecord::Base
|
|||||||
url = url.sub(SiteSetting.s3_cdn_url, Discourse.store.absolute_base_url) if SiteSetting.s3_cdn_url.present?
|
url = url.sub(SiteSetting.s3_cdn_url, Discourse.store.absolute_base_url) if SiteSetting.s3_cdn_url.present?
|
||||||
|
|
||||||
# always try to get the path
|
# always try to get the path
|
||||||
if (uri = URI(url)).scheme
|
uri = URI(url) rescue nil
|
||||||
url = uri.path
|
url = uri.path if uri.try(:scheme)
|
||||||
end
|
|
||||||
|
|
||||||
Upload.find_by(url: url)
|
Upload.find_by(url: url)
|
||||||
end
|
end
|
||||||
|
@ -149,6 +149,10 @@ describe Upload do
|
|||||||
)).to eq(upload)
|
)).to eq(upload)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't blow up with an invalid URI" do
|
||||||
|
expect { Upload.get_from_url("http://ip:port/index.html") }.not_to raise_error
|
||||||
|
end
|
||||||
|
|
||||||
describe "s3 store" do
|
describe "s3 store" do
|
||||||
let(:path) { "/original/3X/1/0/10f73034616a796dfd70177dc54b6def44c4ba6f.png" }
|
let(:path) { "/original/3X/1/0/10f73034616a796dfd70177dc54b6def44c4ba6f.png" }
|
||||||
let(:url) { "//#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com#{path}" }
|
let(:url) { "//#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com#{path}" }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user