Ticket #9016: base64_multipart_decoding.diff
| File base64_multipart_decoding.diff, 2.2 kB (added by bgreenlee, 1 year ago) |
|---|
-
actionpack/test/controller/request_test.rb
old new 712 712 assert_equal 19756, params['files'].size 713 713 end 714 714 715 def test_base64_encoded_file 716 params = process('base64_encoded_file') 717 assert_equal %w(file foo), params.keys.sort 718 assert_equal 'bar', params['foo'] 719 720 file = params['file'] 721 assert_kind_of StringIO, file 722 assert_equal 'file.txt', file.original_filename 723 assert_equal "text/plain\r", file.content_type 724 assert_equal 'contents', file.read 725 end 726 715 727 private 716 728 def process(name) 717 729 File.open(File.join(FIXTURE_PATH, name), 'rb') do |file| -
actionpack/test/fixtures/multipart/base64_encoded_file
old new 1 --AaB03x 2 Content-Disposition: form-data; name="foo" 3 4 bar 5 --AaB03x 6 Content-Disposition: form-data; name="file"; filename="file.txt" 7 Content-Transfer-Encoding: base64 8 Content-Type: text/plain 9 10 Y29udGVudHM= 11 --AaB03x-- -
actionpack/lib/action_controller/request.rb
old new 1 1 require 'tempfile' 2 2 require 'stringio' 3 3 require 'strscan' 4 require 'base64' 4 5 5 6 module ActionController 6 7 # CgiRequest and TestRequest provide concrete implementations. … … 523 524 content_length -= c.size 524 525 end 525 526 527 base64 = /Content-Transfer-Encoding:\s*base64/ni.match(head) 528 526 529 buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{quoted_boundary}([\r\n]{1,2}|--)/n) do 527 content.print $1530 content.print(base64 ? Base64.decode64($1) : $1) 528 531 if "--" == $2 529 532 content_length = -1 530 533 end