mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Merge pull request #926 from netzpirat/fix-s3-images
Don't append the base url to absolute image urls without protocol.
This commit is contained in:
commit
037cbfd648
3 changed files with 23 additions and 1 deletions
|
@ -36,7 +36,7 @@ class CookedPostProcessor
|
|||
|
||||
images.each do |img|
|
||||
src = img['src']
|
||||
src = Discourse.base_url_no_prefix + src if src[0] == "/"
|
||||
src = Discourse.base_url_no_prefix + src if src =~ /^\/[^\/]/
|
||||
|
||||
if src.present?
|
||||
|
||||
|
|
|
@ -81,6 +81,23 @@ describe CookedPostProcessor do
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
context 'with an absolute image path without protocol' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:topic) { Fabricate(:topic, user: user) }
|
||||
let(:post) { Fabricate.build(:post_with_s3_image_url, topic: topic, user: user) }
|
||||
let(:processor) { CookedPostProcessor.new(post) }
|
||||
|
||||
before do
|
||||
ImageSorcery.any_instance.stubs(:convert).returns(false)
|
||||
processor.post_process_images
|
||||
end
|
||||
|
||||
it "doesn't change the protocol" do
|
||||
processor.html.should =~ /src="\/\/bucket\.s3\.amazonaws\.com\/uploads\/6\/4\/123\.png"/
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'link convertor' do
|
||||
|
|
|
@ -34,6 +34,11 @@ Fabricator(:post_with_image_url, from: :post) do
|
|||
"
|
||||
end
|
||||
|
||||
Fabricator(:post_with_s3_image_url, from: :post) do
|
||||
cooked "
|
||||
<img src=\"//bucket.s3.amazonaws.com/uploads/6/4/123.png\">
|
||||
"
|
||||
end
|
||||
|
||||
Fabricator(:basic_reply, from: :post) do
|
||||
user(:coding_horror)
|
||||
|
|
Loading…
Reference in a new issue