From 9852197f83e19939951e700b51f806477ada2769 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 26 Sep 2005 17:59:46 +0000 Subject: 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. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2345 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_controller/cgi_ext/cgi_methods.rb | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb index 3a14311acf..ac2dae9989 100755 --- a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb +++ b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb @@ -88,9 +88,30 @@ class CGIMethods #:nodoc: # test most frequent case first if value.is_a?(String) value - elsif value.respond_to?(:content_type) && !value.content_type.empty? + elsif value.respond_to?(:content_type) # Uploaded file + unless value.respond_to?(:full_original_filename) + class << value + alias_method :full_original_filename, :original_filename + + # Take the basename of the upload's original filename. + # This handles the full Windows paths given by Internet Explorer + # (and perhaps other broken user agents) without affecting + # those which give the lone filename. + # The Windows regexp is adapted from Perl's File::Basename. + def original_filename + if md = /^(?:.*[:\\\/])?(.*)/m.match(full_original_filename) + md.captures.first + else + File.basename full_original_filename + end + end + end + end + + # Return the same value after overriding original_filename. value + elsif value.respond_to?(:read) # Value as part of a multipart request value.read -- cgit v1.2.3