From da44779acdbaf4e3aa59d2c5bcaa606b66394bf8 Mon Sep 17 00:00:00 2001 From: Chris Larsen Date: Sat, 15 Apr 2023 03:47:39 -0400 Subject: [PATCH] Fix issue with multiple children in main branch of if statement --- spec/match_spec.cr | 10 +++++++++- src/liquid/match_visitor.cr | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/spec/match_spec.cr b/spec/match_spec.cr index b15f1a9..6bb925d 100644 --- a/spec/match_spec.cr +++ b/spec/match_spec.cr @@ -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 @@ -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 diff --git a/src/liquid/match_visitor.cr b/src/liquid/match_visitor.cr index 2342286..e3bed94 100644 --- a/src/liquid/match_visitor.cr +++ b/src/liquid/match_visitor.cr @@ -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|