[Haml] Fix an odd outer-whitespace-nuking bug.

This commit is contained in:
Nathan Weizenbaum 2009-11-02 15:12:42 -08:00
parent 98cc1b4e16
commit a13763678a
3 changed files with 21 additions and 5 deletions

View File

@ -9,6 +9,9 @@
if passed a non-string value.
Note that this doesn't affect any HTML escaping when XSS protection is disabled.
* Fixed a bug in outer-whitespace nuking where whitespace-only Ruby strings
blocked whitespace nuking beyond them.
## [2.2.10](http://github.com/nex3/haml/commit/2.2.10)
* Fixed a bug where elements with dynamic attributes and no content

View File

@ -1005,23 +1005,24 @@ END
# Get rid of and whitespace at the end of the buffer
# or the merged text
def rstrip_buffer!
if @to_merge.empty?
def rstrip_buffer!(index = -1)
last = @to_merge[index]
if last.nil?
push_silent("_hamlout.rstrip!", false)
@dont_tab_up_next_text = true
return
end
last = @to_merge.last
case last.first
when :text
last[1].rstrip!
if last[1].empty?
@to_merge.pop
rstrip_buffer!
@to_merge.slice! index
rstrip_buffer! index
end
when :script
last[1].gsub!(/\(haml_temp, (.*?)\);$/, '(haml_temp.rstrip, \1);')
rstrip_buffer! index - 1
else
raise SyntaxError.new("[HAML BUG] Undefined entry in Haml::Precompiler@to_merge.")
end

View File

@ -321,6 +321,18 @@ HTML
HAML
end
def test_outer_whitespace_nuke_with_empty_script
assert_equal(<<HTML, render(<<HAML))
<p>
foo<a></a></p>
HTML
%p
foo
= " "
%a>
HAML
end
def test_both_case_indentation_work_with_deeply_nested_code
result = <<RESULT
<h2>