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

Only check script lines for continuation keywords

If a non-script line starts with a keyword it can cause errors.
This commit is contained in:
Matt Wildig 2014-11-29 02:34:11 +00:00
parent 79e66dfa8e
commit 52501ccfce
2 changed files with 15 additions and 5 deletions

View file

@ -209,7 +209,15 @@ module Haml
return unless line.tabs <= @template_tabs && @template_tabs > 0
to_close = @template_tabs - line.tabs
to_close.times {|i| close unless to_close - 1 - i == 0 && mid_block_keyword?(line.text)}
to_close.times {|i| close unless to_close - 1 - i == 0 && continuation_script?(line.text)}
end
def continuation_script?(text)
text[0] == SILENT_SCRIPT && mid_block_keyword?(text)
end
def mid_block_keyword?(text)
MID_BLOCK_KEYWORDS.include?(block_keyword(text))
end
# Processes a single line of Haml.
@ -256,10 +264,6 @@ module Haml
keyword[0] || keyword[1]
end
def mid_block_keyword?(text)
MID_BLOCK_KEYWORDS.include?(block_keyword(text))
end
def push(node)
@parent.children << node
node.parent = @parent

View file

@ -116,6 +116,12 @@ module Haml
refute node.value[:revealed]
end
test "only script lines are checked for continuation keywords" do
haml = "- if true\n setup\n- else\n else\n"
node = parse(haml).children[0]
assert_equal(3, node.children.size)
end
private
def parse(haml, options = nil)