mirror of
https://github.com/discourse/discourse.git
synced 2025-02-22 09:13:11 +08:00
FIX: FastImage#size
returns nil
if it can't fetch the image size.
This commit is contained in:
parent
fcc86d3a9d
commit
00078a438b
@ -116,13 +116,16 @@ class CookedPostProcessor
|
|||||||
if w > 0 || h > 0
|
if w > 0 || h > 0
|
||||||
w = w.to_f
|
w = w.to_f
|
||||||
h = h.to_f
|
h = h.to_f
|
||||||
original_width, original_height = get_size(img["src"]).map {|integer| integer.to_f}
|
|
||||||
|
return unless original_image_size = get_size(img["src"])
|
||||||
|
original_width, original_height = original_image_size.map(&:to_f)
|
||||||
|
|
||||||
if w > 0
|
if w > 0
|
||||||
ratio = w/original_width
|
ratio = w/original_width
|
||||||
return [w.floor, (original_height*ratio).floor]
|
[w.floor, (original_height*ratio).floor]
|
||||||
else
|
else
|
||||||
ratio = h/original_height
|
ratio = h/original_height
|
||||||
return [(original_width*ratio).floor, h.floor]
|
[(original_width*ratio).floor, h.floor]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -149,7 +152,7 @@ class CookedPostProcessor
|
|||||||
return unless is_valid_image_url?(absolute_url)
|
return unless is_valid_image_url?(absolute_url)
|
||||||
|
|
||||||
# we can *always* crawl our own images
|
# we can *always* crawl our own images
|
||||||
return unless SiteSetting.crawl_images? || Discourse.store.has_been_uploaded?(url)
|
return unless SiteSetting.crawl_images || Discourse.store.has_been_uploaded?(url)
|
||||||
|
|
||||||
@size_cache[url] ||= FastImage.size(absolute_url)
|
@size_cache[url] ||= FastImage.size(absolute_url)
|
||||||
rescue Zlib::BufError # FastImage.size raises BufError for some gifs
|
rescue Zlib::BufError # FastImage.size raises BufError for some gifs
|
||||||
|
@ -267,6 +267,12 @@ describe CookedPostProcessor do
|
|||||||
expect(cpp.get_size("http://foo.bar/image2.png")).to eq([100, 200])
|
expect(cpp.get_size("http://foo.bar/image2.png")).to eq([100, 200])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns nil if FastImage can't get the original size" do
|
||||||
|
Discourse.store.class.any_instance.expects(:has_been_uploaded?).returns(true)
|
||||||
|
FastImage.expects(:size).returns(nil)
|
||||||
|
expect(cpp.get_size("http://foo.bar/image3.png")).to eq(nil)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user