diff --git a/.travis.yml b/.travis.yml index 7c282d6..b7018a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: ruby rvm: - - 1.9.2 - 1.9.3 - 2.0.0 - 2.1.8 diff --git a/fastimage.gemspec b/fastimage.gemspec index dd6760a..8d49323 100644 --- a/fastimage.gemspec +++ b/fastimage.gemspec @@ -20,7 +20,6 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.rubygems_version = %q{1.3.6} s.summary = %q{FastImage - Image info fast} - s.add_runtime_dependency 'addressable', '~> 2' s.add_development_dependency 'fakeweb', '~> 1.3' # Note rake 11 drops support for ruby 1.9.2 s.add_development_dependency('rake', '~> 10.5') diff --git a/lib/fastimage.rb b/lib/fastimage.rb index 7e7b3c7..2413671 100644 --- a/lib/fastimage.rb +++ b/lib/fastimage.rb @@ -55,12 +55,18 @@ # require 'net/https' -require 'addressable/uri' require 'delegate' require 'pathname' require 'zlib' require 'base64' +require 'uri' +# see http://stackoverflow.com/questions/5208851/i/41048816#41048816 +if RUBY_VERSION < "2.2" + module URI + DEFAULT_PARSER = Parser.new(:HOSTNAME => "(?:(?:[a-zA-Z\\d](?:[-\\_a-zA-Z\\d]*[a-zA-Z\\d])?)\\.)*(?:[a-zA-Z](?:[-\\_a-zA-Z\\d]*[a-zA-Z\\d])?)\\.?") + end +end class FastImage attr_reader :size, :type, :content_length, :orientation @@ -190,8 +196,8 @@ class FastImage fetch_using_base64(uri) else begin - @parsed_uri = Addressable::URI.parse(uri) - rescue Addressable::URI::InvalidURIError + @parsed_uri = URI.parse(uri) + rescue URI::InvalidURIError fetch_using_file_open else if @parsed_uri.scheme == "http" || @parsed_uri.scheme == "https" @@ -241,14 +247,14 @@ class FastImage if res.is_a?(Net::HTTPRedirection) && @redirect_count < 4 @redirect_count += 1 begin - newly_parsed_uri = Addressable::URI.parse(res['Location']) + newly_parsed_uri = URI.parse(res['Location']) # The new location may be relative - check for that if newly_parsed_uri.scheme != "http" && newly_parsed_uri.scheme != "https" @parsed_uri.path = res['Location'] else @parsed_uri = newly_parsed_uri end - rescue Addressable::URI::InvalidURIError + rescue URI::InvalidURIError else fetch_using_http_from_parsed_uri break @@ -289,11 +295,11 @@ class FastImage def proxy_uri begin if @options[:proxy] - proxy = Addressable::URI.parse(@options[:proxy]) + proxy = URI.parse(@options[:proxy]) else - proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? Addressable::URI.parse(ENV['http_proxy']) : nil + proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? URI.parse(ENV['http_proxy']) : nil end - rescue Addressable::URI::InvalidURIError + rescue URI::InvalidURIError proxy = nil end proxy @@ -303,9 +309,9 @@ class FastImage proxy = proxy_uri if proxy - @http = Net::HTTP::Proxy(proxy.host, proxy.port).new(@parsed_uri.host, @parsed_uri.inferred_port) + @http = Net::HTTP::Proxy(proxy.host, proxy.port).new(@parsed_uri.host, @parsed_uri.port) else - @http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.inferred_port) + @http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.port) end @http.use_ssl = (@parsed_uri.scheme == "https") @http.verify_mode = OpenSSL::SSL::VERIFY_NONE diff --git a/test/test.rb b/test/test.rb index 3f3ae39..34edbe5 100644 --- a/test/test.rb +++ b/test/test.rb @@ -375,5 +375,8 @@ class FastImageTest < Test::Unit::TestCase assert_raises(FastImage::ImageFetchFailure) do FastImage.type("data:", :raise_on_failure => true) end + + def test_should_work_with_domains_with_underscores + assert_equal :gif, FastImage.type("http://foo_bar.inbro.net/images/p.gif") end end