Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #99 from droppedoncaprica/tempFileFix
Browse files Browse the repository at this point in the history
Fix Tempfile reference being returned as nil
  • Loading branch information
Zachary Scott committed Jul 26, 2016
2 parents f6ce66f + 4b482b7 commit bce9100
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rack/protection/escaped_params.rb
@@ -1,5 +1,6 @@
require 'rack/protection'
require 'rack/utils'
require 'tempfile'

begin
require 'escape_utils'
Expand Down Expand Up @@ -66,6 +67,7 @@ def escape(object)
when Hash then escape_hash(object)
when Array then object.map { |o| escape(o) }
when String then escape_string(object)
when Tempfile then object
else nil
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/rack/protection/escaped_params_spec.rb
Expand Up @@ -37,5 +37,25 @@
get '/?95df8d9bf5237ad08df3115ee74dcb10'
expect(body).to eq('hi')
end

it 'leaves TempFiles untouched' do
mock_app do |env|
request = Rack::Request.new(env)
[200, {'Content-Type' => 'text/plain'}, [request.params['file'][:filename] + "\n" + \
request.params['file'][:tempfile].read + "\n" + \
request.params['other']]]
end

temp_file = File.open('_escaped_params_tmp_file', 'w')
begin
temp_file.write('hello world')
temp_file.close

post '/', :file => Rack::Test::UploadedFile.new(temp_file.path), :other => '<bar>'
expect(body).to eq("_escaped_params_tmp_file\nhello world\n&lt;bar&gt;")
ensure
File.unlink(temp_file.path)
end
end
end
end

0 comments on commit bce9100

Please sign in to comment.