mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-10-05 00:02:33 -04:00
Merge pull request #139 from sdsykes/fix/NoMethodError
Handle nil being passed as uri
This commit is contained in:
commit
b65d75c8a3
@ -85,6 +85,8 @@ class FastImage
|
||||
end
|
||||
class CannotParseImage < FastImageException # :nodoc:
|
||||
end
|
||||
class BadImageURI < FastImageException # :nodoc:
|
||||
end
|
||||
|
||||
DefaultTimeout = 2 unless const_defined?(:DefaultTimeout)
|
||||
|
||||
@ -228,6 +230,8 @@ class FastImage
|
||||
:size
|
||||
end
|
||||
|
||||
raise BadImageURI if uri.nil?
|
||||
|
||||
@type, @state = nil
|
||||
|
||||
if uri.respond_to?(:read)
|
||||
@ -254,7 +258,7 @@ class FastImage
|
||||
Errno::ENETUNREACH, ImageFetchFailure, Net::HTTPBadResponse, EOFError, Errno::ENOENT,
|
||||
OpenSSL::SSL::SSLError
|
||||
raise ImageFetchFailure if @options[:raise_on_failure]
|
||||
rescue UnknownImageType
|
||||
rescue UnknownImageType, BadImageURI
|
||||
raise if @options[:raise_on_failure]
|
||||
rescue CannotParseImage
|
||||
if @options[:raise_on_failure]
|
||||
|
10
test/test.rb
10
test/test.rb
@ -481,4 +481,14 @@ class FastImageTest < Test::Unit::TestCase
|
||||
FastImage.size(TestUrl + "a.CRW", :raise_on_failure=>true)
|
||||
end
|
||||
end
|
||||
|
||||
def test_returns_nil_when_uri_is_nil
|
||||
assert_equal nil, FastImage.size(nil)
|
||||
end
|
||||
|
||||
def test_raises_when_uri_is_nil_and_raise_on_failure_is_set
|
||||
assert_raises(FastImage::BadImageURI) do
|
||||
FastImage.size(nil, :raise_on_failure => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user