Don't append the base url to absolute image urls without protocol.
This commit is contained in:
parent
571e62a27a
commit
d2e45cb8fd
|
@ -36,7 +36,7 @@ class CookedPostProcessor
|
||||||
|
|
||||||
images.each do |img|
|
images.each do |img|
|
||||||
src = img['src']
|
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?
|
if src.present?
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,23 @@ describe CookedPostProcessor do
|
||||||
end
|
end
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
context 'link convertor' do
|
context 'link convertor' do
|
||||||
|
|
|
@ -34,6 +34,11 @@ Fabricator(:post_with_image_url, from: :post) do
|
||||||
"
|
"
|
||||||
end
|
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
|
Fabricator(:basic_reply, from: :post) do
|
||||||
user(:coding_horror)
|
user(:coding_horror)
|
||||||
|
|
Loading…
Reference in New Issue