From 422bafd66a8084f0e037509b97c2a2f837c2c885 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Wed, 12 Nov 2014 16:12:00 -0500 Subject: [PATCH] Fix #warnings taking exponential time to compute --- lib/liquid/block_body.rb | 2 +- test/integration/template_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index 14a3696a..c892d939 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -62,7 +62,7 @@ module Liquid def warnings all_warnings = [] nodelist.each do |node| - all_warnings.concat(node.warnings) if node.respond_to?(:warnings) && node.warnings + all_warnings.concat(node.warnings) if node.respond_to?(:warnings) end all_warnings end diff --git a/test/integration/template_test.rb b/test/integration/template_test.rb index 9a4c979f..a754b3f0 100644 --- a/test/integration/template_test.rb +++ b/test/integration/template_test.rb @@ -37,6 +37,16 @@ class TemplateTest < Minitest::Test assert_equal 'from instance assigns', t.parse("{{ foo }}").render! end + def test_warnings_is_not_exponential_time + str = "false" + 100.times do + str = "{% if true %}true{% else %}#{str}{% endif %}" + end + + t = Template.parse(str) + assert_equal [], t.warnings + end + def test_instance_assigns_persist_on_same_template_parsing_between_renders t = Template.new.parse("{{ foo }}{% assign foo = 'foo' %}{{ foo }}") assert_equal 'foo', t.render!