Changeset 2345
- Timestamp:
- 09/26/05 17:59:46 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/text_helper.rb (modified) (1 diff)
- trunk/actionpack/test/controller/cgi_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r2326 r2345 1 1 *SVN* 2 3 * Shorten IE file upload path to filename only to match other browsers. #1507 [court3nay@gmail.com] 2 4 3 5 * 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 89 89 if value.is_a?(String) 90 90 value 91 elsif value.respond_to?(:content_type) && !value.content_type.empty?91 elsif value.respond_to?(:content_type) 92 92 # 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. 93 113 value 114 94 115 elsif value.respond_to?(:read) 95 116 # Value as part of a multipart request trunk/actionpack/lib/action_view/helpers/text_helper.rb
r2265 r2345 302 302 ) 303 303 ([[:punct:]]|\s|<|$) # trailing text 304 /x 304 /x unless const_defined?(:AUTO_LINK_RE) 305 305 306 306 # Turns all urls into clickable links. trunk/actionpack/test/controller/cgi_test.rb
r1677 r2345 4 4 require 'action_controller/cgi_ext/cgi_methods' 5 5 require 'stringio' 6 7 class MockUploadedFile < StringIO8 def content_type9 "img/jpeg"10 end11 12 def original_filename13 "my_file.doc"14 end15 end16 6 17 7 class CGITest < Test::Unit::TestCase … … 117 107 118 108 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') 120 112 121 113 input = { … … 123 115 "array_of_stringios" => [[ StringIO.new("One"), StringIO.new("Two") ]], 124 116 "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")]], 126 119 "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 ] 128 123 } 129 124 … … 133 128 "mixed_types_array" => [ "Three", "NotStringIO" ], 134 129 "mixed_types_as_checkboxes" => { 135 "strings" => {136 "nested" =>[ mock_file, "String", "StringIO" ]130 "strings" => { 131 "nested" => [ file, "String", "StringIO" ] 137 132 }, 138 133 }, 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 142 146 } 143 147 } 144 148 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 146 159 end 147 160