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

Changeset 2345

Show
Ignore:
Timestamp:
09/26/05 17:59:46 (3 years ago)
Author:
bitsweat
Message:

r3573@asus: jeremy | 2005-09-26 11:38:44 -0700
Ticket 1507 - IE file uploads give the filename as a full Windows path, but Ruby on UNIX doesn't know how to File.basename('C:\\blah\blah.foo').
r3574@asus: jeremy | 2005-09-26 14:32:11 -0700
Get rid of constant redefine warning.
r3575@asus: jeremy | 2005-09-26 14:33:07 -0700
Override the file upload's original_filename singleton method in CGIMethods.get_typed_value.
r3576@asus: jeremy | 2005-09-26 14:33:49 -0700
Unit test overridden original_filename against normal filenames and full Windows paths.
r3577@asus: jeremy | 2005-09-26 14:33:57 -0700
Update change log.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r2326 r2345  
    11*SVN* 
     2 
     3* Shorten IE file upload path to filename only to match other browsers.  #1507 [court3nay@gmail.com] 
    24 
    35* Fix open/save dialog in IE not opening files send with send_file/send_data, #2279 [Thomas Fuchs] 
  • trunk/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb

    r2151 r2345  
    8989      if value.is_a?(String) 
    9090        value 
    91       elsif value.respond_to?(:content_type) && !value.content_type.empty? 
     91      elsif value.respond_to?(:content_type) 
    9292        # Uploaded file 
     93        unless value.respond_to?(:full_original_filename) 
     94          class << value 
     95            alias_method :full_original_filename, :original_filename 
     96 
     97            # Take the basename of the upload's original filename. 
     98            # This handles the full Windows paths given by Internet Explorer 
     99            # (and perhaps other broken user agents) without affecting 
     100            # those which give the lone filename. 
     101            # The Windows regexp is adapted from Perl's File::Basename. 
     102            def original_filename 
     103              if md = /^(?:.*[:\\\/])?(.*)/m.match(full_original_filename) 
     104                md.captures.first 
     105              else 
     106                File.basename full_original_filename 
     107              end 
     108            end 
     109          end 
     110        end 
     111 
     112        # Return the same value after overriding original_filename. 
    93113        value 
     114 
    94115      elsif value.respond_to?(:read) 
    95116        # Value as part of a multipart request 
  • trunk/actionpack/lib/action_view/helpers/text_helper.rb

    r2265 r2345  
    302302                        ) 
    303303                        ([[:punct:]]|\s|<|$)    # trailing text 
    304                        /x 
     304                       /x unless const_defined?(:AUTO_LINK_RE) 
    305305 
    306306        # Turns all urls into clickable links. 
  • trunk/actionpack/test/controller/cgi_test.rb

    r1677 r2345  
    44require 'action_controller/cgi_ext/cgi_methods' 
    55require 'stringio' 
    6  
    7 class MockUploadedFile < StringIO 
    8   def content_type 
    9     "img/jpeg" 
    10   end 
    11  
    12   def original_filename 
    13     "my_file.doc" 
    14   end 
    15 end 
    166 
    177class CGITest < Test::Unit::TestCase 
     
    117107   
    118108  def test_parse_params_from_multipart_upload 
    119     mock_file = MockUploadedFile.new 
     109    mockup = Struct.new(:content_type, :original_filename) 
     110    file = mockup.new('img/jpeg', 'foo.jpg') 
     111    ie_file = mockup.new('img/jpeg', 'c:\\Documents and Settings\\foo\\Desktop\\bar.jpg') 
    120112   
    121113    input = { 
     
    123115      "array_of_stringios" => [[ StringIO.new("One"), StringIO.new("Two") ]], 
    124116      "mixed_types_array" => [[ StringIO.new("Three"), "NotStringIO" ]], 
    125       "mixed_types_as_checkboxes[strings][nested]" => [[ mock_file, "String", StringIO.new("StringIO")]], 
     117      "mixed_types_as_checkboxes[strings][nested]" => [[ file, "String", StringIO.new("StringIO")]], 
     118      "ie_mixed_types_as_checkboxes[strings][nested]" => [[ ie_file, "String", StringIO.new("StringIO")]], 
    126119      "products[string]" => [ StringIO.new("Apple Computer") ], 
    127       "products[file]" => [ mock_file ] 
     120      "products[file]" => [ file ], 
     121      "ie_products[string]" => [ StringIO.new("Microsoft") ], 
     122      "ie_products[file]" => [ ie_file ] 
    128123    } 
    129124     
     
    133128      "mixed_types_array" => [ "Three", "NotStringIO" ], 
    134129      "mixed_types_as_checkboxes" => { 
    135          "strings"=> { 
    136             "nested"=>[ mock_file, "String", "StringIO" ] 
     130         "strings" => { 
     131            "nested" => [ file, "String", "StringIO" ] 
    137132         }, 
    138133      }, 
    139       "products"  => { 
    140         "string"  => "Apple Computer", 
    141         "file"    => mock_file 
     134      "ie_mixed_types_as_checkboxes" => { 
     135         "strings" => { 
     136            "nested" => [ ie_file, "String", "StringIO" ] 
     137         }, 
     138      }, 
     139      "products" => { 
     140        "string" => "Apple Computer", 
     141        "file" => file 
     142      }, 
     143      "ie_products" => { 
     144        "string" => "Microsoft", 
     145        "file" => ie_file 
    142146      } 
    143147    } 
    144148 
    145     assert_equal expected_output, CGIMethods.parse_request_parameters(input) 
     149    params = CGIMethods.parse_request_parameters(input) 
     150    assert_equal expected_output, params 
     151 
     152    # Lone filenames are preserved. 
     153    assert_equal 'foo.jpg', params['mixed_types_as_checkboxes']['strings']['nested'].first.original_filename 
     154    assert_equal 'foo.jpg', params['products']['file'].original_filename 
     155 
     156    # But full Windows paths are reduced to their basename. 
     157    assert_equal 'bar.jpg', params['ie_mixed_types_as_checkboxes']['strings']['nested'].first.original_filename 
     158    assert_equal 'bar.jpg', params['ie_products']['file'].original_filename 
    146159  end 
    147160