From 3a2eb31b0634406fd876cb35d41c49045aafef58 Mon Sep 17 00:00:00 2001 From: Benjamin Jackson Date: Sat, 26 Oct 2013 11:49:24 -0400 Subject: [PATCH] Switched to using Addressable for URI parsing due to issues with hostnames that contain underscores. Cf. http://www.cloudspace.com/blog/2009/05/26/replacing-rubys-uri-with-addressable/ --- Gemfile | 1 + Gemfile.lock | 17 +++++++++++++++++ README.textile | 2 +- fastimage.gemspec | 2 ++ lib/fastimage.rb | 16 ++++++++-------- 5 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..901f575 --- /dev/null +++ b/Gemfile @@ -0,0 +1 @@ +gemspec \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..7ae5797 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,17 @@ +PATH + remote: . + specs: + fastimage (1.5.2) + addressable (~> 2.3.5) + +GEM + specs: + addressable (2.3.5) + fakeweb (1.3.0) + +PLATFORMS + ruby + +DEPENDENCIES + fakeweb (~> 1.3.0) + fastimage! diff --git a/README.textile b/README.textile index 3cc072f..a178b46 100644 --- a/README.textile +++ b/README.textile @@ -16,7 +16,7 @@ You only need supply the uri, and FastImage will do the rest. h2. Features -Fastimage can also read local (and other) files, and uses the open-uri library to do so. +Fastimage can also read local (and other) files, and uses the Addressable library to do so. FastImage will automatically read from any object that responds to :read - for instance an IO object if that is passed instead of a URI. diff --git a/fastimage.gemspec b/fastimage.gemspec index 9e7c9ed..94a790b 100644 --- a/fastimage.gemspec +++ b/fastimage.gemspec @@ -35,6 +35,8 @@ 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.3.5' + s.add_development_dependency 'fakeweb', '~> 1.3.0' s.test_files = [ "test/test.rb" ] diff --git a/lib/fastimage.rb b/lib/fastimage.rb index 304c293..82757f2 100644 --- a/lib/fastimage.rb +++ b/lib/fastimage.rb @@ -11,7 +11,7 @@ # FastImage knows about GIF, JPEG, BMP, TIFF and PNG files. # # FastImage can also read files from the local filesystem by supplying the path instead of a uri. -# In this case FastImage uses the open-uri library to read the file in chunks of 256 bytes until +# In this case FastImage uses the Addressable library to read the file in chunks of 256 bytes until # it has enough. This is possibly a useful bandwidth-saving feature if the file is on a network # attached disk rather than truly local. # @@ -41,7 +41,7 @@ # require 'net/https' -require 'open-uri' +require 'addressable/uri' require 'fastimage/fbr.rb' class FastImage @@ -161,8 +161,8 @@ class FastImage fetch_using_read(uri) else begin - @parsed_uri = URI.parse(uri) - rescue URI::InvalidURIError + @parsed_uri = Addressable::URI.parse(uri) + rescue Addressable::URI::InvalidURIError fetch_using_open_uri else if @parsed_uri.scheme == "http" || @parsed_uri.scheme == "https" @@ -209,14 +209,14 @@ class FastImage if res.is_a?(Net::HTTPRedirection) && @redirect_count < 4 @redirect_count += 1 begin - newly_parsed_uri = URI.parse(res['Location']) + newly_parsed_uri = Addressable::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 URI::InvalidURIError + rescue Addressable::URI::InvalidURIError else fetch_using_http_from_parsed_uri break @@ -239,8 +239,8 @@ class FastImage def proxy_uri begin - proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? URI.parse(ENV['http_proxy']) : nil - rescue URI::InvalidURIError + proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? Addressable::URI.parse(ENV['http_proxy']) : nil + rescue Addressable::URI::InvalidURIError proxy = nil end proxy