dragonfly 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dragonfly might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afe5f948bd5e670d97c683750532bb5612d5f754
4
- data.tar.gz: 9d267698e7df156ccae311e7ab79b66989d89343
3
+ metadata.gz: c443c8f0fc5b7be3523df81d24f3fa02d4cde7a1
4
+ data.tar.gz: b68fd67ac67553ec180304a099a37e6625db4692
5
5
  SHA512:
6
- metadata.gz: e3e76e51825eb12335a794e48c017d86f695ee9b43164c048f0dde267da4ac9b5c9a8bf0c6e9936f3daa4c6f12255257933b3148664e8d66973ff403d72e9cd1
7
- data.tar.gz: 9f256720478cc17ae88e32a3264db632b439283cedb8d3deb2989f1b6ec3802fbfa11acc521cfed55ba23af90f229c72e00b4558b564c9b8b24f3d0ce0a69410
6
+ metadata.gz: 3af5d4adc707c1089838cda7b65242ad2c3820dabf7c498e0ffdddb71768cc68f2eb970d7682fdac020e3fa416fb44b7bcb6f01706aedff1a72c56003a0b7be9
7
+ data.tar.gz: b29fe47d2ce93f8f638d116b2964c345a591b237731ba68fcc22fad87428ed9bc02f3cf3663907f7b4a90270198a07f5a57638b3c75a3880ff8035eb77c9c00d
data/History.md CHANGED
@@ -1,3 +1,9 @@
1
+ 1.0.4 (2014-04-11)
2
+ ===================
3
+ Fixes
4
+ -----
5
+ - fetch_url is more forgiving - assume escaped, if not escape
6
+
1
7
  1.0.3 (2014-01-28)
2
8
  ===================
3
9
  Fixes
data/README.md CHANGED
@@ -54,7 +54,7 @@ Installation
54
54
 
55
55
  or in your Gemfile
56
56
  ```ruby
57
- gem 'dragonfly', '~> 1.0.3'
57
+ gem 'dragonfly', '~> 1.0.4'
58
58
  ```
59
59
 
60
60
  Require with
@@ -15,6 +15,7 @@ module Dragonfly
15
15
  end
16
16
  class CannotHandle < RuntimeError; end
17
17
  class TooManyRedirects < RuntimeError; end
18
+ class BadURI < RuntimeError; end
18
19
 
19
20
  def init
20
21
  job.url_attributes.name = filename
@@ -25,12 +26,12 @@ module Dragonfly
25
26
  end
26
27
 
27
28
  def url
28
- @url ||= uri =~ /^\w+:/ ? uri : "http://#{uri}"
29
+ @url ||= uri =~ /^\w+:[^\d]/ ? uri : "http://#{uri}"
29
30
  end
30
31
 
31
32
  def filename
32
33
  return if data_uri?
33
- @filename ||= URI.parse(url).path[/[^\/]+$/]
34
+ @filename ||= parse_url(url).path[/[^\/]+$/]
34
35
  end
35
36
 
36
37
  def data_uri?
@@ -41,14 +42,16 @@ module Dragonfly
41
42
  if data_uri?
42
43
  update_from_data_uri
43
44
  else
44
- data = get(URI.escape(url))
45
+ data = get(url)
45
46
  job.content.update(data, 'name' => filename)
46
47
  end
47
48
  end
48
49
 
50
+ private
51
+
49
52
  def get(url, redirect_limit=10)
50
53
  raise TooManyRedirects, "url #{url} redirected too many times" if redirect_limit == 0
51
- response = Net::HTTP.get_response(URI.parse(url))
54
+ response = Net::HTTP.get_response(parse_url(url))
52
55
  case response
53
56
  when Net::HTTPSuccess then response.body || ""
54
57
  when Net::HTTPRedirection then get(response['location'], redirect_limit-1)
@@ -70,6 +73,16 @@ module Dragonfly
70
73
  end
71
74
  end
72
75
 
76
+ def parse_url(url)
77
+ URI.parse(url)
78
+ rescue URI::InvalidURIError
79
+ begin
80
+ URI.parse(URI.escape(url))
81
+ rescue URI::InvalidURIError => e
82
+ raise BadURI, e.message
83
+ end
84
+ end
85
+
73
86
  end
74
87
  end
75
88
  end
@@ -1,3 +1,3 @@
1
1
  module Dragonfly
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -124,7 +124,7 @@ describe "a configured imagemagick app" do
124
124
  describe "identify" do
125
125
  it "gives the output of the command line" do
126
126
  image.identify.should =~ /280/
127
- image.identify("-format %h").should == "355\n"
127
+ image.identify("-format %h").chomp.should == "355"
128
128
  end
129
129
  end
130
130
 
@@ -6,7 +6,7 @@ describe Dragonfly::Job::FetchUrl do
6
6
  let (:job) { Dragonfly::Job.new(app) }
7
7
 
8
8
  before(:each) do
9
- stub_request(:get, %r{http://place\.com/.*}).to_return(:body => 'result!')
9
+ stub_request(:get, %r{http://place\.com.*}).to_return(:body => 'result!')
10
10
  end
11
11
 
12
12
  it "adds a step" do
@@ -35,7 +35,8 @@ describe Dragonfly::Job::FetchUrl do
35
35
  "http://place.com",
36
36
  "place.com/",
37
37
  "place.com/stuff/",
38
- "place.com/?things"
38
+ "place.com/?things",
39
+ "place.com:8080"
39
40
  ].each do |url|
40
41
  it "doesn't set the name if there isn't one, e.g. for #{url}" do
41
42
  job.fetch_url!(url)
@@ -52,7 +53,8 @@ describe Dragonfly::Job::FetchUrl do
52
53
  "place.com/dung.beetle",
53
54
  "http://place.com/dung.beetle",
54
55
  "place.com/stuff/dung.beetle",
55
- "place.com/dung.beetle?morethings"
56
+ "place.com/dung.beetle?morethings",
57
+ "place.com:8080/dung.beetle"
56
58
  ].each do |url|
57
59
  it "sets the name if there is one, e.g. for #{url}" do
58
60
  job.fetch_url!(url)
@@ -65,6 +67,13 @@ describe Dragonfly::Job::FetchUrl do
65
67
  end
66
68
  end
67
69
 
70
+ it "works with domain:port" do
71
+ stub_request(:get, "localhost:8080").to_return(:body => "okay!")
72
+ thing = job.fetch_url('localhost:8080')
73
+ thing.name.should be_nil
74
+ thing.data.should == 'okay!'
75
+ end
76
+
68
77
  it "should raise an error if not found" do
69
78
  stub_request(:get, "notfound.com").to_return(:status => 404, :body => "BLAH")
70
79
  expect{
@@ -85,24 +94,46 @@ describe Dragonfly::Job::FetchUrl do
85
94
  }
86
95
  end
87
96
 
88
- it "should follow redirects" do
89
- stub_request(:get, "redirectme.com").to_return(:status => 302, :headers => {'Location' => 'http://ok.com'})
90
- stub_request(:get, "ok.com").to_return(:body => "OK!")
91
- job.fetch_url('redirectme.com').data.should == 'OK!'
92
- end
97
+ describe "escaping" do
98
+ before do
99
+ stub_request(:get, "escapedurl.com/escaped%20url.jpg").to_return(:body => "OK!")
100
+ end
101
+
102
+ it "works with escaped urls" do
103
+ job.fetch_url('escapedurl.com/escaped%20url.jpg').data.should == 'OK!'
104
+ end
105
+
106
+ it "tries to escape unescaped urls" do
107
+ job.fetch_url('escapedurl.com/escaped url.jpg').data.should == 'OK!'
108
+ end
93
109
 
94
- it "follows redirects to https" do
95
- stub_request(:get, "redirectme.com").to_return(:status => 302, :headers => {'Location' => 'https://ok.com'})
96
- stub_request(:get, /ok.com/).to_return(:body => "OK!")
97
- job.fetch_url('redirectme.com').data.should == 'OK!'
110
+ it "still blows up with bad urls" do
111
+ expect {
112
+ job.fetch_url('1:{')
113
+ }.to raise_error(Dragonfly::Job::FetchUrl::BadURI)
114
+ end
98
115
  end
99
116
 
100
- it "raises if redirecting too many times" do
101
- stub_request(:get, "redirectme.com").to_return(:status => 302, :headers => {'Location' => 'http://redirectme-back.com'})
102
- stub_request(:get, "redirectme-back.com").to_return(:status => 302, :headers => {'Location' => 'http://redirectme.com'})
103
- expect {
104
- job.fetch_url('redirectme.com').apply
105
- }.to raise_error(Dragonfly::Job::FetchUrl::TooManyRedirects)
117
+ describe "redirects" do
118
+ it "should follow redirects" do
119
+ stub_request(:get, "redirectme.com").to_return(:status => 302, :headers => {'Location' => 'http://ok.com'})
120
+ stub_request(:get, "ok.com").to_return(:body => "OK!")
121
+ job.fetch_url('redirectme.com').data.should == 'OK!'
122
+ end
123
+
124
+ it "follows redirects to https" do
125
+ stub_request(:get, "redirectme.com").to_return(:status => 302, :headers => {'Location' => 'https://ok.com'})
126
+ stub_request(:get, /ok.com/).to_return(:body => "OK!")
127
+ job.fetch_url('redirectme.com').data.should == 'OK!'
128
+ end
129
+
130
+ it "raises if redirecting too many times" do
131
+ stub_request(:get, "redirectme.com").to_return(:status => 302, :headers => {'Location' => 'http://redirectme-back.com'})
132
+ stub_request(:get, "redirectme-back.com").to_return(:status => 302, :headers => {'Location' => 'http://redirectme.com'})
133
+ expect {
134
+ job.fetch_url('redirectme.com').apply
135
+ }.to raise_error(Dragonfly::Job::FetchUrl::TooManyRedirects)
136
+ end
106
137
  end
107
138
 
108
139
  describe "data uris" do
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-28 00:00:00.000000000 Z
11
+ date: 2014-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: multi_json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.5'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activemodel
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: |-
@@ -90,9 +90,9 @@ extra_rdoc_files:
90
90
  - LICENSE
91
91
  - README.md
92
92
  files:
93
- - .gitignore
94
- - .rspec
95
- - .travis.yml
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".travis.yml"
96
96
  - Gemfile
97
97
  - History.md
98
98
  - LICENSE
@@ -240,17 +240,17 @@ require_paths:
240
240
  - lib
241
241
  required_ruby_version: !ruby/object:Gem::Requirement
242
242
  requirements:
243
- - - '>='
243
+ - - ">="
244
244
  - !ruby/object:Gem::Version
245
245
  version: '0'
246
246
  required_rubygems_version: !ruby/object:Gem::Requirement
247
247
  requirements:
248
- - - '>='
248
+ - - ">="
249
249
  - !ruby/object:Gem::Version
250
250
  version: '0'
251
251
  requirements: []
252
252
  rubyforge_project:
253
- rubygems_version: 2.1.11
253
+ rubygems_version: 2.2.1
254
254
  signing_key:
255
255
  specification_version: 4
256
256
  summary: Ideal gem for handling attachments in Rails, Sinatra and Rack applications.