nex3/haml — Issue #462: Production-only bug using blocks in helpers
Author: urbanautomaton
Created: 2011-11-24 23:59:15+00:00
State: open

Hi,

I've encountered a strange output-mangling bug that occurs when you use a helper that accepts a block within a haml template, e.g.:

def restrict_access(role)
yield if current_user && current_user.has_role(role)
end

- restrict_access("admin") do
= link_to "Delete Everything", destruction_of_the_world_path

Another user, @scottwb, has created an [example app](https://github.com/scottwb/haml-block-bug) illustrating precisely this issue, tested in numerous ruby, rails and haml versions.

I believe this may relate to a long-abandoned issue, #93, which claimed that `#capture_haml` exhibited different behaviour when `Haml::Template.options[:ugly]` was set to `true`. A quick perusal of the haml source indicates that the only place the rails environment is referenced is in [`lib/haml/template.rb#45`](https://github.com/nex3/haml/blob/master/lib/haml/template.rb#L45), which just so happens to set that option to true.

I will continue to dig deeper, however I'm completely new to the haml codebase, so if there's any information I can provide that would allow someone else to make a speedier diagnosis, I'd be very happy to do so - just let me know.

Cheers,
Simon