[Haml] Fix an obscure if statement bug.

For example:

    - if foo
      - if bar
      - else
        baz
This commit is contained in:
Nathan Weizenbaum 2010-07-06 16:17:42 -07:00
parent 380c7773b7
commit 21436193f4
3 changed files with 13 additions and 11 deletions

View File

@ -7,6 +7,8 @@
* Allow CSS-style classes and ids to contain colons.
* Fix an obscure bug with if statements.
## 3.0.13
[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.12).

View File

@ -242,29 +242,20 @@ END
# Handle stuff like - end.join("|")
@to_close_stack.last << false if text =~ /^-\s*end\b/ && !block_opened?
case_stmt = text =~ /^-\s*case\b/
keyword = mid_block_keyword?(text)
block = block_opened? && !keyword
# It's important to preserve tabulation modification for keywords
# that involve choosing between posible blocks of code.
if %w[else elsif when].include?(keyword)
# @to_close_stack may not have a :script on top
# when the preceding "- if" has nothing nested
if @to_close_stack.last && @to_close_stack.last.first == :script
@dont_indent_next_line, @dont_tab_up_next_text = @to_close_stack.last[1..2]
else
push_and_tabulate([:script, @dont_indent_next_line, @dont_tab_up_next_text])
end
@dont_indent_next_line, @dont_tab_up_next_text = @to_close_stack.last[1..2]
# when is unusual in that either it will be indented twice,
# or the case won't have created its own indentation
if keyword == "when"
push_and_tabulate([:script, @dont_indent_next_line, @dont_tab_up_next_text, false])
end
elsif block || case_stmt
push_and_tabulate([:script, @dont_indent_next_line, @dont_tab_up_next_text])
elsif block && case_stmt
elsif block || text =~ /^-\s*(case|if)\b/
push_and_tabulate([:script, @dont_indent_next_line, @dont_tab_up_next_text])
end
when FILTER; start_filtered(text[1..-1].downcase)

View File

@ -668,6 +668,15 @@ HTML
- else
foo
HAML
assert_equal(<<HTML, render(<<HAML))
foo
HTML
- if true
- if false
- else
foo
HAML
end
def test_html_attributes_with_hash