Skip to content

Commit

Permalink
daveg: adding the addressable gem, and sprinkling some Addressable pa…
Browse files Browse the repository at this point in the history
…rsing into the parse_uri method.
  • Loading branch information
dgiunta authored and Mark Evans committed Jul 2, 2014
1 parent 23eb589 commit d2bfa25
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions dragonfly.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency("rack", [">= 0"])
spec.add_runtime_dependency("multi_json", ["~> 1.0"])
spec.add_runtime_dependency("addressable", ["~> 2.3"])

spec.add_development_dependency("rspec", ["~> 2.5"])
spec.add_development_dependency("webmock")
Expand Down
6 changes: 5 additions & 1 deletion lib/dragonfly/job/fetch_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'net/http'
require 'base64'
require 'dragonfly/job/step'
require 'addressable/uri'

module Dragonfly
class Job
Expand Down Expand Up @@ -84,7 +85,10 @@ def parse_url(url)
URI.parse(url)
rescue URI::InvalidURIError
begin
URI.parse(URI.escape(url))
encoded_uri = Addressable::URI.parse(url).normalize.to_s
URI.parse(encoded_uri)
rescue Addressable::URI::InvalidURIError => e
raise BadURI, e.message
rescue URI::InvalidURIError => e
raise BadURI, e.message
end
Expand Down
6 changes: 3 additions & 3 deletions spec/dragonfly/job/fetch_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@

describe "escaping" do
before do
stub_request(:get, "escapedurl.com/escaped%20url.jpg").to_return(:body => "OK!")
stub_request(:get, "escapedurl.com/escaped%20url%5B1%5D.jpg").to_return(:body => "OK!")
end

it "works with escaped urls" do
job.fetch_url('escapedurl.com/escaped%20url.jpg').data.should == 'OK!'
job.fetch_url('escapedurl.com/escaped%20url%5B1%5D.jpg').data.should == 'OK!'
end

it "tries to escape unescaped urls" do
job.fetch_url('escapedurl.com/escaped url.jpg').data.should == 'OK!'
job.fetch_url('escapedurl.com/escaped url[1].jpg').data.should == 'OK!'
end

it "still blows up with bad urls" do
Expand Down

0 comments on commit d2bfa25

Please sign in to comment.