Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9016: base64_multipart_decoding.diff

File base64_multipart_decoding.diff, 2.2 kB (added by bgreenlee, 1 year ago)

Less brain-dead check for base64 Content-Transfer-Encoding

  • actionpack/test/controller/request_test.rb

    old new  
    712712    assert_equal 19756, params['files'].size 
    713713  end 
    714714 
     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 
    715727  private 
    716728    def process(name) 
    717729      File.open(File.join(FIXTURE_PATH, name), 'rb') do |file| 
  • actionpack/test/fixtures/multipart/base64_encoded_file

    old new  
     1--AaB03x 
     2Content-Disposition: form-data; name="foo" 
     3 
     4bar 
     5--AaB03x 
     6Content-Disposition: form-data; name="file"; filename="file.txt" 
     7Content-Transfer-Encoding: base64 
     8Content-Type: text/plain 
     9 
     10Y29udGVudHM= 
     11--AaB03x-- 
  • actionpack/lib/action_controller/request.rb

    old new  
    11require 'tempfile' 
    22require 'stringio' 
    33require 'strscan' 
     4require 'base64' 
    45 
    56module ActionController 
    67  # CgiRequest and TestRequest provide concrete implementations. 
     
    523524              content_length -= c.size 
    524525            end 
    525526 
     527            base64 = /Content-Transfer-Encoding:\s*base64/ni.match(head) 
     528               
    526529            buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{quoted_boundary}([\r\n]{1,2}|--)/n) do 
    527               content.print $1 
     530              content.print(base64 ? Base64.decode64($1) : $1) 
    528531              if "--" == $2 
    529532                content_length = -1 
    530533              end