dragonfly 0.9.2 → 0.9.3

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.

data/History.md CHANGED
@@ -1,3 +1,11 @@
1
+ 0.9.3 (2011-06-03)
2
+ ==================
3
+ Fixes
4
+ -----
5
+ - TempObject#to_file sets file permissions 644 - copying wasn't previously guaranteeing this
6
+ - Added TempObject#close and closed?, which Rack uses to clean up tempfiles
7
+ - replaced '/' characters with '~' in base64 encoded urls (they were confusing url recognition)
8
+
1
9
  0.9.2 (2011-05-19)
2
10
  ==================
3
11
  Features
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.9.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dragonfly}
8
- s.version = "0.9.2"
8
+ s.version = "0.9.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark Evans"]
12
- s.date = %q{2011-05-19}
12
+ s.date = %q{2011-06-03}
13
13
  s.description = %q{Dragonfly is a framework that enables on-the-fly processing for any content type.
14
14
  It is especially suited to image handling. Its uses range from image thumbnails to standard attachments to on-demand text generation.}
15
15
  s.email = %q{mark@new-bamboo.co.uk}
@@ -10,12 +10,12 @@ module Dragonfly
10
10
  extend self # So we can do Serializer.b64_encode, etc.
11
11
 
12
12
  def b64_encode(string)
13
- Base64.encode64(string).tr("\n=",'')
13
+ Base64.encode64(string).tr("\n=",'').tr('/','~')
14
14
  end
15
15
 
16
16
  def b64_decode(string)
17
17
  padding_length = string.length % 4
18
- Base64.decode64(string + '=' * padding_length)
18
+ Base64.decode64(string.tr('~','/') + '=' * padding_length)
19
19
  end
20
20
 
21
21
  def marshal_encode(object)
@@ -74,7 +74,7 @@ module Dragonfly
74
74
 
75
75
  def url_mapper
76
76
  @url_mapper ||= UrlMapper.new(url_format,
77
- :job => '[\w+]',
77
+ :job => '[\w+~]',
78
78
  :basename => '[^\/]',
79
79
  :format => '[^\.]'
80
80
  )
@@ -32,6 +32,9 @@ module Dragonfly
32
32
  #
33
33
  class TempObject
34
34
 
35
+ # Exceptions
36
+ class Closed < RuntimeError; end
37
+
35
38
  # Class configuration
36
39
  class << self
37
40
 
@@ -69,10 +72,12 @@ module Dragonfly
69
72
  attr_reader :original_filename
70
73
 
71
74
  def data
75
+ raise Closed, "can't read data as TempObject has been closed" if closed?
72
76
  @data ||= file{|f| f.read }
73
77
  end
74
78
 
75
79
  def tempfile
80
+ raise Closed, "can't read from tempfile as TempObject has been closed" if closed?
76
81
  @tempfile ||= begin
77
82
  case
78
83
  when @data
@@ -117,6 +122,7 @@ module Dragonfly
117
122
  File.open(path, 'wb'){|f| f.write(@data) }
118
123
  else
119
124
  FileUtils.cp(self.path, path)
125
+ File.chmod(0644, path)
120
126
  end
121
127
  File.new(path, 'rb')
122
128
  end
@@ -125,6 +131,16 @@ module Dragonfly
125
131
  @data ? StringIO.open(@data, 'rb', &block) : file(&block)
126
132
  end
127
133
 
134
+ def close
135
+ @tempfile.close! if @tempfile
136
+ @data = nil
137
+ @closed = true
138
+ end
139
+
140
+ def closed?
141
+ !!@closed
142
+ end
143
+
128
144
  def inspect
129
145
  content_string = case
130
146
  when @data
@@ -23,6 +23,20 @@ describe Dragonfly::Serializer do
23
23
  end
24
24
  end
25
25
 
26
+ describe "replacing the '/' character in b64_encode" do
27
+ before(:each) do
28
+ @string = (127..255).map{|c| c.chr }.join
29
+ end
30
+ it "should replace '/' with '~'" do
31
+ b64_encode(@string).should_not =~ /\//
32
+ b64_encode(@string).should =~ /[\w+]+~[\w+]+/
33
+ end
34
+ it "should correctly encode and decode to the same string" do
35
+ str = b64_decode(b64_encode(@string))
36
+ str.should == @string
37
+ end
38
+ end
39
+
26
40
  [
27
41
  :hello,
28
42
  nil,
@@ -59,7 +59,16 @@ describe Dragonfly::Server do
59
59
  response.status.should == 200
60
60
  response.body.should == 'eggs'
61
61
  end
62
-
62
+
63
+ it "should work ok with ~ symbols" do
64
+ funny_filename = (127..255).map{|c| c.chr }.join
65
+ @app.datastore.should_receive(:retrieve).with(funny_filename).and_return "EGGS"
66
+ # the following is the url for 'fetch(funny_filename)'
67
+ response = request(@server, '/media/BAhbBlsHOgZmIgGBf4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr~AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u~w8fLz9PX29~j5+vv8~f7~')
68
+ response.status.should == 200
69
+ response.body.should == 'EGGS'
70
+ end
71
+
63
72
  it "should return a cacheable response" do
64
73
  url = "/media/#{@job.serialize}"
65
74
  cache = Rack::Cache.new(@server, :entitystore => 'heap:/')
@@ -135,6 +135,10 @@ describe Dragonfly::TempObject do
135
135
  file.should be_a(File)
136
136
  file.read.should == 'HELLO'
137
137
  end
138
+ it "should have 644 permissions" do
139
+ @temp_object.to_file(@filename)
140
+ File::Stat.new(@filename).mode.to_s(8).should =~ /644$/
141
+ end
138
142
  end
139
143
 
140
144
  end
@@ -159,6 +163,34 @@ describe Dragonfly::TempObject do
159
163
  parts.last.length.should <= 3001
160
164
  end
161
165
  end
166
+
167
+ describe "closing" do
168
+ before(:each) do
169
+ @temp_object = new_temp_object("wassup")
170
+ end
171
+ it "should delete its tempfile" do
172
+ tempfile = @temp_object.tempfile
173
+ path = tempfile.path
174
+ path.should_not be_empty
175
+ @temp_object.close
176
+ File.exist?(path).should be_false
177
+ end
178
+ %w(tempfile file data).each do |method|
179
+ it "should raise error when calling #{method}" do
180
+ @temp_object.close
181
+ expect{
182
+ @temp_object.send(method)
183
+ }.to raise_error(Dragonfly::TempObject::Closed)
184
+ end
185
+ end
186
+ it "should not report itself as closed to begin with" do
187
+ @temp_object.should_not be_closed
188
+ end
189
+ it "should report itself as closed after closing" do
190
+ @temp_object.close
191
+ @temp_object.should be_closed
192
+ end
193
+ end
162
194
 
163
195
  end
164
196
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dragonfly
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.2
5
+ version: 0.9.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mark Evans
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-19 00:00:00 +01:00
13
+ date: 2011-06-03 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -401,7 +401,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
401
401
  requirements:
402
402
  - - ">="
403
403
  - !ruby/object:Gem::Version
404
- hash: 3194904429017796395
404
+ hash: 3515566453882631482
405
405
  segments:
406
406
  - 0
407
407
  version: "0"