Permalink
Browse files

Fixed the "URL Extension" bug a different way than GarthSnyder did. I…

…nstead of checking the validity of the extension, we now properly parse URL's for their extensions.
  • Loading branch information...
1 parent 8480390 commit 3b27aa1a2ed90e8b9487591f3fec123fedeeed4a @hcatlin hcatlin committed Feb 28, 2011
Showing with 5 additions and 4 deletions.
  1. +3 −2 lib/mini_magick.rb
  2. +2 −2 test/image_test.rb
View
@@ -73,13 +73,14 @@ def from_blob(blob, ext = nil)
# @param file_or_url [String] Either a local file path or a URL that open-uri can read
# @param ext [String] Specify the extension you want to read it as
# @return [Image] The loaded image
- def open(file_or_url, ext = File.extname(file_or_url))
+ def open(file_or_url, ext = nil)
file_or_url = file_or_url.to_s # Force it to be a String... hell or highwater
if file_or_url.include?("://")
require 'open-uri'
- ext = nil unless ext and ext =~ /^\.\w{2,8}$/
+ ext ||= File.extname(URI.parse(file_or_url).path)
self.read(Kernel::open(file_or_url), ext)
else
+ ext ||= File.extname(file_or_url)
File.open(file_or_url, "rb") do |f|
self.read(f, ext)
end
View
@@ -53,13 +53,13 @@ def test_image_new
def test_remote_image
image = Image.open("http://www.google.com/images/logos/logo.png")
- image.valid?
+ assert image.valid?
image.destroy!
end
def test_remote_image_with_complex_url
image = Image.open("http://a0.twimg.com/a/1296609216/images/fronts/logo_withbird_home.png?extra=foo&plus=bar")
- image.valid?
+ assert image.valid?
image.destroy!
end

0 comments on commit 3b27aa1

Please sign in to comment.