Skip to content

Commit

Permalink
Fix issue with multiple children in main branch of if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLarsen authored and hugopl committed Apr 19, 2023
1 parent bf03148 commit da44779
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion spec/match_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe Template do
tpl.matches?("false").should eq false
end

it "should match unless statement", tags: "current" do
it "should match unless statement" do
tpl = Parser.parse("{% unless var == true %}false{% endif %}")

tpl.matches?("false").should eq true
Expand Down Expand Up @@ -89,4 +89,12 @@ describe Template do
tpl.matches?("even odd even ").should eq true
tpl.matches?("even noteven even").should eq false
end

it "should match nested if statement", tags: "current" do
tpl = Parser.parse("{% if count %}Count: {% for x in 1..3 %}N{{ x }}{% endfor %}{% else %}Reverse Count: {% for x in 9..7 %}R{{ x }}{% endfor %}{% endif %}")

tpl.matches?("Count: N1N2N3").should eq true
tpl.matches?("Reverse Count: R9R8R7").should eq true
tpl.matches?("").should eq false
end
end
2 changes: 1 addition & 1 deletion src/liquid/match_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Liquid
end

def visit(node : Conditional) : String
child_nodes = node.children.map { |e| self.visit e }
child_nodes = [node.children.map { |e| self.visit e }.join]

if elsif_arr = node.elsif
elsif_arr.each do |alt|
Expand Down

0 comments on commit da44779

Please sign in to comment.