FIX: Don't raise an error when the img attribute cannot be found

This commit is contained in:
Robin Ward 2017-05-08 15:35:31 -04:00
parent afe04b8bbb
commit 009e120e13
2 changed files with 9 additions and 0 deletions

View File

@ -158,6 +158,9 @@ class CookedPostProcessor
absolute_url = url
absolute_url = Discourse.base_url_no_prefix + absolute_url if absolute_url =~ /^\/[^\/]/
return unless absolute_url
# FastImage fails when there's no scheme
absolute_url = SiteSetting.scheme + ":" + absolute_url if absolute_url.start_with?("//")

View File

@ -310,6 +310,12 @@ describe CookedPostProcessor do
expect(cpp.get_size_from_attributes(img)).to eq([33, 100])
end
it "doesn't raise an error with a weird url" do
img = { 'src' => nil, 'height' => 100}
SiteSetting.stubs(:crawl_images?).returns(true)
expect(cpp.get_size_from_attributes(img)).to be_nil
end
end
context ".get_size_from_image_sizes" do