Skip to content

Commit

Permalink
It should not mess with file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdurtschi committed Sep 1, 2010
1 parent a0f70e8 commit 1b1b299
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/rack/sanitize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def sanitize(value)
value.map {|v| sanitize(v)}
elsif value.is_a?(String)
::Sanitize.clean(value, @config)
else
value
end
end

Expand Down
Binary file added spec/fixtures/gnu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion spec/rack/sanitize_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../spec_helper'
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe Rack::Sanitize do
it "should sanitize GETs" do
Expand Down Expand Up @@ -70,4 +70,26 @@
it "should default to sanitizing both GETs and POSTs" do

end

describe "file uploads" do
before do
@fixtures_dir = File.join(File.dirname(__FILE__), '..', 'fixtures')
@gnu_file = File.join(@fixtures_dir, 'gnu.png')
@uploaded_file = File.join(@fixtures_dir, 'uploaded_file.png')
end

after do
if File.exists?(@uploaded_file)
FileUtils.rm(@uploaded_file)
end
end

it "should not mess with file uploads" do
file = Rack::Test::UploadedFile.new(@gnu_file, 'image/png')

post '/fileupload', {"file" => file}
File.exists?(@uploaded_file).should be_true
FileUtils.compare_file(@gnu_file, @uploaded_file).should be_true
end
end
end
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class PotentialVictim < Sinatra::Base
post '/post' do
"POSTs: #{Rack::Utils.unescape(request.POST.to_query)}"
end

post '/fileupload' do
tempfile = params["file"][:tempfile]
FileUtils.copy_file(tempfile.path, File.join(File.dirname(__FILE__), 'fixtures', 'uploaded_file.png'))
end
end

Spec::Runner.configure do |config|
Expand Down

0 comments on commit 1b1b299

Please sign in to comment.