Merge branch 'master' of github.com:sdsykes/fastimage

This commit is contained in:
Stephen Sykes 2019-09-05 22:51:40 +03:00
commit 6c7cdcd475
5 changed files with 22 additions and 12 deletions

View File

@ -1,11 +1,10 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.8
- 2.2.4
- 2.3.0
- 2.5.1
- 2.2.9
- 2.3.8
- 2.4.5
- 2.5.5
- 2.6.2
sudo: false
# uncomment this line if your project needs to run something other than `rake`:

View File

@ -214,7 +214,8 @@ class FastImage
raise SizeNotFound if @options[:raise_on_failure] && @property == :size && !@size
rescue Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET,
ImageFetchFailure, Net::HTTPBadResponse, EOFError, Errno::ENOENT, OpenSSL::SSL::SSLError
Errno::ENETUNREACH, ImageFetchFailure, Net::HTTPBadResponse, EOFError, Errno::ENOENT,
OpenSSL::SSL::SSLError
raise ImageFetchFailure if @options[:raise_on_failure]
rescue NoMethodError # 1.8.7p248 can raise this due to a net/http bug
raise ImageFetchFailure if @options[:raise_on_failure]
@ -321,7 +322,7 @@ class FastImage
proxy = proxy_uri
if proxy
@http = Net::HTTP::Proxy(proxy.host, proxy.port).new(@parsed_uri.host, @parsed_uri.port)
@http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new(@parsed_uri.host, @parsed_uri.port)
else
@http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.port)
end
@ -579,10 +580,10 @@ class FastImage
d = @stream.read(32)[14..28]
header = d.unpack("C")[0]
result = if header == 40
d[4..-1].unpack('l<l<')
else
result = if header == 12
d[4..8].unpack('SS')
else
d[4..-1].unpack('l<l<')
end
# ImageHeight is expressed in pixels. The absolute value is necessary because ImageHeight can be negative

BIN
test/fixtures/test_coreheader.bmp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
test/fixtures/test_v5header.bmp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -11,6 +11,8 @@ FixturePath = File.join(PathHere, "fixtures")
GoodFixtures = {
"test.bmp"=>[:bmp, [40, 27]],
"test2.bmp"=>[:bmp, [1920, 1080]],
"test_coreheader.bmp"=>[:bmp, [40, 27]],
"test_v5header.bmp"=>[:bmp, [40, 27]],
"test.gif"=>[:gif, [17, 32]],
"test.jpg"=>[:jpeg, [882, 470]],
"test.png"=>[:png, [30, 20]],
@ -140,6 +142,14 @@ class FastImageTest < Test::Unit::TestCase
end
end
def test_should_raise_image_fetch_failure_error_if_net_unreach_exception_happens
FakeWeb.register_uri(:get, "http://example.com", :exception => Errno::ENETUNREACH)
assert_raises(FastImage::ImageFetchFailure) do
FastImage.size("http://example.com", :raise_on_failure=>true)
end
end
def test_should_raise_unknown_image_typ_when_file_is_non_svg_xml
assert_raises(FastImage::UnknownImageType) do
FastImage.size(TestUrl + "test.xml", :raise_on_failure=>true)
@ -429,7 +439,7 @@ class FastImageTest < Test::Unit::TestCase
def test_should_return_content_length_for_data_uri_images
assert_equal DataUriImageContentLength, FastImage.new(DataUriImage).content_length
end
def test_canon_raw_formats_are_not_recognised_as_tiff
assert_raises(FastImage::UnknownImageType) do
FastImage.size(TestUrl + "a.CR2", :raise_on_failure=>true)