The summary says it all really. I like empty form fields to result in a nil in the params hash when submitted. Currently they result in an empty string.
Regardless of whether this was a delibarate choice or not, it should at least be consistent with what happens for empty GET parameters (which current result in a nil). Otherwise controller behaviour can change in tricky and hard-to-spot ways merely as a result of changing a form's method from POST to GET.
Here is a trivial replacement for CGIMethods.get_typed_value (in cgi_ext/cgi_methods.rb) which seems to fix this for me, giving nils in both cases.
def CGIMethods.get_typed_value(value)
# test most frequent case first
if value.is_a?(String)
value.empty? ? nil : value
elsif value.respond_to?(:content_type) && ! value.content_type.blank?
# 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
v = value.read
v.empty? ? nil : v
elsif value.class == Array
value.collect { |v| CGIMethods.get_typed_value(v) }
else
# other value (neither string nor a multipart request)
v = value.to_s
v.empty? ? nil : v
end
end