[Haml] Use _hamlout.buffer rather than _erbout to concatenate to.

Using _erbout means that if _hamlout.buffer is set to something else,
e.g. with ActionView's with_output_buffer, the Haml text is
concatenated onto the wrong buffer.

This is basically reverting eb1e034734.
This commit is contained in:
Nathan Weizenbaum 2009-10-14 17:57:12 -07:00
parent 43f817b86f
commit 169e9e5fb8
3 changed files with 27 additions and 4 deletions

View File

@ -3,6 +3,12 @@
* Table of contents
{:toc}
## 2.2.9 (Unreleased)
* Fixed a bug where Haml's text was concatenated to the wrong buffer
under certain circumstances.
This was mostly an issue under Rails when using methods like `capture`.
## [2.2.8](http://github.com/nex3/haml/commit/2.2.8)
* Fixed a potential XSS issue with HTML escaping and wacky Unicode nonsense.

View File

@ -313,7 +313,7 @@ END
@precompiled <<
if @options[:ugly]
"_erbout << \"#{text}\";"
"_hamlout.buffer << \"#{text}\";"
else
"_hamlout.push_text(\"#{text}\", #{tab_change}, #{@dont_tab_up_next_text.inspect});"
end
@ -375,7 +375,7 @@ END
push_silent "haml_temp = #{text}"
newline_now
push_and_tabulate([:loud, "_erbout << #{no_format ? "#{output_temp}.to_s;" : out}",
push_and_tabulate([:loud, "_hamlout.buffer << #{no_format ? "#{output_temp}.to_s;" : out}",
!(opts[:in_tag] || opts[:nuke_inner_whitespace] || @options[:ugly])])
end

View File

@ -84,8 +84,8 @@ class TemplateTest < Test::Unit::TestCase
base
end
def render(text)
Haml::Engine.new(text).to_html(@base)
def render(text, opts = {})
Haml::Engine.new(text, opts).to_html(@base)
end
def load_result(name)
@ -184,6 +184,23 @@ class TemplateTest < Test::Unit::TestCase
Haml::Template.options = {}
end
def test_with_output_buffer_with_ugly
assert_equal(<<HTML, render(<<HAML, :ugly => true))
<p>
foo
baz
</p>
HTML
%p
foo
- with_output_buffer do
bar
= "foo".gsub(/./) do |s|
- s.ord
baz
HAML
end
def test_exceptions_should_work_correctly
begin
render("- raise 'oops!'")