Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Never return stored content from content_for when a block is given #2799

Merged
merged 2 commits into from
Sep 5, 2011
Merged

Never return stored content from content_for when a block is given #2799

merged 2 commits into from
Sep 5, 2011

Conversation

tomstuart
Copy link
Contributor

There is a bug in content_for. It should only return stored content when no block has been provided, but instead it returns stored content when the block generates a blank buffer and has a nil return value, which is what happens in a situation like this:

<% content_for :foo do %>
  <% if something_falsy %>
    foo
  <% end %>
  <% if something_else_falsy %>
    bar
  <% end %>
<% end %>

Ultimately this is because capture returns nil (vs '') when the resulting buffer is blank?, but that's apparently intended behaviour, so it's better to fix content_for to explicitly check block_given? rather than relying on the truthiness of capture(&block).

The bug provokes a deprecation warning in 3.0.x (see #2794); there is no such warning in 3.1.x, but it's still unintended behaviour.

The capture helper may return nil when evaluation of the block has
produced a buffer which contains only whitespace, but that doesn't
mean content_for should return stored content.
@josevalim
Copy link
Contributor

Sounds great. Can we have a patch for master as well?

@spastorino
Copy link
Contributor

@tomstuart patch looks good. Just one thing please provide pull requests for master only next time, unless is something specific for 3-1-stable. If we need it for 3-1-stable we will backport or ask you to do so :). Thanks for your work ❤️

spastorino added a commit that referenced this pull request Sep 5, 2011
Never return stored content from content_for when a block is given
@spastorino spastorino merged commit a2baf03 into rails:3-1-stable Sep 5, 2011
@spastorino
Copy link
Contributor

I've already ported to master, thanks again

spastorino added a commit that referenced this pull request Sep 5, 2011
Never return stored content from content_for when a block is given
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants