Merge pull request #139 from sdsykes/fix/NoMethodError

Handle nil being passed as uri
This commit is contained in:
Sam 2023-04-11 11:26:30 +10:00 committed by GitHub
commit b65d75c8a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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]

View File

@ -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