rack-raw-upload 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,7 +12,7 @@ Rack::RawUpload performs this conversion when all these conditions are met:
12
12
  2. The mimetype is one of
13
13
  * application/x-www-form-urlencoded
14
14
  * multipart/form-data
15
- 3. The request includes body data
15
+ 3. The Content-Length is greater than 0
16
16
 
17
17
  ## Configuration
18
18
 
@@ -3,7 +3,7 @@ require 'tmpdir' # Needed in 1.8.7 to access Dir::tmpdir
3
3
  module Rack
4
4
  class RawUpload
5
5
 
6
- VERSION = '1.0.10'
6
+ VERSION = '1.0.11'
7
7
 
8
8
  def initialize(app, opts = {})
9
9
  @app = app
@@ -76,7 +76,7 @@ module Rack
76
76
  upload_path?(env['PATH_INFO']) &&
77
77
  %{POST PUT}.include?(env['REQUEST_METHOD']) &&
78
78
  content_type_of_raw_file?(env['CONTENT_TYPE']) &&
79
- input_is_present?(env['rack.input'])
79
+ env['CONTENT_LENGTH'].to_i > 0
80
80
  end
81
81
 
82
82
  def literal_path_match?(request_path, candidate)
@@ -98,10 +98,6 @@ module Rack
98
98
  end
99
99
  end
100
100
 
101
- def input_is_present?(input)
102
- !input.nil? && (!input.respond_to?(:empty?) || !input.empty?)
103
- end
104
-
105
101
  def random_string
106
102
  (0...8).map{65.+(rand(25)).chr}.join
107
103
  end
@@ -26,7 +26,7 @@ class RawUploadTest < Test::Unit::TestCase
26
26
  def upload(env = {})
27
27
  env = {
28
28
  'CONTENT_TYPE' => 'application/octet-stream',
29
- 'rack.input' => @file
29
+ 'rack.input' => @file,
30
30
  }.merge(env)
31
31
  do_request(env)
32
32
  end
@@ -34,15 +34,18 @@ class RawUploadTest < Test::Unit::TestCase
34
34
  def post(env = {})
35
35
  env = {
36
36
  'CONTENT_TYPE' => 'multipart/form-data',
37
- 'rack.input' => StringIO.new('things=stuff')
37
+ 'rack.input' => StringIO.new('things=stuff'),
38
38
  }.merge(env)
39
39
  do_request(env)
40
40
  end
41
41
 
42
42
  def do_request(env = {})
43
+ input = env['rack.input']
44
+ length = input.respond_to?(:size) ? input.size : File.size(input.path)
43
45
  env = {
44
46
  'REQUEST_METHOD' => 'POST',
45
47
  'PATH_INFO' => '/some/path',
48
+ 'CONTENT_LENGTH' => length.to_s,
46
49
  }.merge(env)
47
50
  request(env['PATH_INFO'], env)
48
51
  end
@@ -78,6 +81,11 @@ class RawUploadTest < Test::Unit::TestCase
78
81
  assert_successful_non_upload
79
82
  end
80
83
 
84
+ should "not work when there is no input" do
85
+ upload('rack.input' => StringIO.new(''))
86
+ assert_successful_non_upload
87
+ end
88
+
81
89
  # "stuff" should be something like "boundary=----WebKitFormBoundaryeKPeU4p65YgercgO",
82
90
  # but if I do that here, Rack tries to be clever and the test breaks
83
91
  should "not work with Content-Type 'multipart/form-data; stuff'" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-raw-upload
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 10
10
- version: 1.0.10
9
+ - 11
10
+ version: 1.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pablo Brasero