1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Fix a long-standing case-parsing bug.

Thanks to Aman Gupta for the bug report.
This commit is contained in:
Nathan Weizenbaum 2008-10-29 20:36:53 -07:00
parent 68bd782b63
commit 9817621ede
2 changed files with 37 additions and 3 deletions

View file

@ -209,9 +209,11 @@ END
push_silent(text[1..-1], true)
newline_now
if (@block_opened && !mid_block_keyword?(text)) || text[1..-1].split(' ', 2)[0] == "case"
push_and_tabulate([:script])
end
case_stmt = text[1..-1].split(' ', 2)[0] == "case"
block = @block_opened && !mid_block_keyword?(text)
push_and_tabulate([:script]) if block || case_stmt
push_and_tabulate(nil) if block && case_stmt
when FILTER; start_filtered(text[1..-1].downcase)
when DOCTYPE
return render_doctype(text) if text[0...3] == '!!!'
@ -371,6 +373,7 @@ END
when :loud; close_loud value
when :filtered; close_filtered value
when :haml_comment; close_haml_comment
when nil; close_nil
end
end
@ -420,6 +423,10 @@ END
@template_tabs -= 1
end
def close_nil
@template_tabs -= 1
end
# Iterates through the classes and ids supplied through <tt>.</tt>
# and <tt>#</tt> syntax, and returns a hash with them as attributes,
# that can then be merged with another attributes hash.

View file

@ -198,6 +198,33 @@ RESULT
SOURCE
end
# Mostly a regression test
def test_both_case_indentation_work_with_deeply_nested_code
result = <<RESULT
<h2>
other
</h2>
RESULT
assert_equal(result, render(<<HAML))
- case 'other'
- when 'test'
%h2
hi
- when 'other'
%h2
other
HAML
assert_equal(result, render(<<HAML))
- case 'other'
- when 'test'
%h2
hi
- when 'other'
%h2
other
HAML
end
# HTML escaping tests
def test_ampersand_equals_should_escape