aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/upload.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch/http/upload.rb')
-rw-r--r--actionpack/lib/action_dispatch/http/upload.rb18
1 files changed, 8 insertions, 10 deletions
diff --git a/actionpack/lib/action_dispatch/http/upload.rb b/actionpack/lib/action_dispatch/http/upload.rb
index 94fa747a79..ce8c2729e9 100644
--- a/actionpack/lib/action_dispatch/http/upload.rb
+++ b/actionpack/lib/action_dispatch/http/upload.rb
@@ -4,11 +4,12 @@ module ActionDispatch
attr_accessor :original_filename, :content_type, :tempfile, :headers
def initialize(hash)
+ @tempfile = hash[:tempfile]
+ raise(ArgumentError, ':tempfile is required') unless @tempfile
+
@original_filename = encode_filename(hash[:filename])
@content_type = hash[:type]
@headers = hash[:head]
- @tempfile = hash[:tempfile]
- raise(ArgumentError, ':tempfile is required') unless @tempfile
end
def read(*args)
@@ -16,18 +17,15 @@ module ActionDispatch
end
# Delegate these methods to the tempfile.
- [:open, :path, :rewind, :size].each do |method|
+ [:open, :path, :rewind, :size, :eof?].each do |method|
class_eval "def #{method}; @tempfile.#{method}; end"
end
-
+
private
+
def encode_filename(filename)
- # Encode the filename in the utf8 encoding, unless it is nil or we're in 1.8
- if "ruby".encoding_aware? && filename
- filename.force_encoding("UTF-8").encode!
- else
- filename
- end
+ # Encode the filename in the utf8 encoding, unless it is nil
+ filename.force_encoding("UTF-8").encode! if filename
end
end