content-legth should be eq 0 when render nothing: true #14350

Closed
wants to merge 1 commit into
from

Projects

None yet

6 participants

@arthurnn
Ruby on Rails member

Problem

When doing render nothing: true, it should render a body == ""

This how Rails behaves since 2009, because of a Safari bug.

As far as I can see the history, seems like this problem was introduced by this commit 53596d0 . Before that change if you only pass a nothing: true body would be nil.

[fixes #14336]

review @rafaelfranca @carlosantoniodasilva @sikachu

I am not sure about the implementation. looks dirty, but I couldnt think a better way. I am opened for suggestions.

If it is all good, I can add a CHANGELOG.

@carlosantoniodasilva carlosantoniodasilva and 1 other commented on an outdated diff Mar 11, 2014
actionpack/lib/action_controller/metal/rendering.rb
@@ -67,9 +67,10 @@ def _normalize_options(options) #:nodoc:
options[:html] = ERB::Util.html_escape(options[:html])
end
- if options.delete(:nothing) || _any_render_format_is_nil?(options)
- options[:body] = " "
- end
+ body = options[:body]
+ body = nil if nothing = (options.delete(:nothing) == true)
+ body = " " if _any_render_format_is_nil?(options)
+ options[:body] = body if body || nothing
@carlosantoniodasilva
carlosantoniodasilva Mar 11, 2014

How about this?

if options.delete(:nothing)
  options[:body] = nil
elsif _any_render_format_is_nil?(options)
  options[:body] = " "
end
@arthurnn
arthurnn Mar 11, 2014

that wont work for the case:

render nothing: true, body: nil

which should add a body " "

@carlosantoniodasilva
carlosantoniodasilva Mar 11, 2014

And why you'd do such a thing? Do we have tests that cover that scenario?

@sikachu
Ruby on Rails member

render :nothing => true adds a space since it was a workaround for bug in Safari. It has been that way since 2009. See cb0f8fd and 807df4f for the implementation. Unless Safari doesn't have that bug anymore, we could change it to return an empty string.

But that'd be for 5.0, not 4.2.

/cc @dhh and @jeremy, do you guys have any input on this?

@dhh
Ruby on Rails member
@arthurnn arthurnn content-legth should be eq 0 when render nothing: true 25abec1
@arthurnn
Ruby on Rails member

Updated PR with @carlosantoniodasilva suggestion.
Indeed this is not a regression(I changed the PR description so people wont get confused).

Agree with @sikachu @dhh , This is an old behaviour. will be good, if we could fix it. Otherwise I am ok to close. For the time being I will leave it open until we are sure we cannot fix this behaviour.

@robin850 robin850 added the actionpack label Mar 16, 2014
@jeremy
Ruby on Rails member

Moving over to #14883, verifies whether the old behavior is no longer required.

@jeremy jeremy closed this Apr 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment