From 648a4888af6b95c1da2d61690f86daba1a33dbdb Mon Sep 17 00:00:00 2001 From: Justin Li Date: Thu, 14 May 2015 15:02:20 -0400 Subject: [PATCH] Pop the for_stack register in an ensure --- lib/liquid/tags/for.rb | 3 ++- test/integration/error_handling_test.rb | 19 ------------------- test/integration/tags/for_tag_test.rb | 10 ++++++++++ test/test_helper.rb | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/liquid/tags/for.rb b/lib/liquid/tags/for.rb index 578002a..95defc7 100644 --- a/lib/liquid/tags/for.rb +++ b/lib/liquid/tags/for.rb @@ -132,8 +132,9 @@ module Liquid end end - for_stack.pop result + ensure + for_stack.pop end protected diff --git a/test/integration/error_handling_test.rb b/test/integration/error_handling_test.rb index c21b4b4..468808c 100644 --- a/test/integration/error_handling_test.rb +++ b/test/integration/error_handling_test.rb @@ -1,24 +1,5 @@ require 'test_helper' -class ErrorDrop < Liquid::Drop - def standard_error - raise Liquid::StandardError, 'standard error' - end - - def argument_error - raise Liquid::ArgumentError, 'argument error' - end - - def syntax_error - raise Liquid::SyntaxError, 'syntax error' - end - - def exception - raise Exception, 'exception' - end - -end - class ErrorHandlingTest < Minitest::Test include Liquid diff --git a/test/integration/tags/for_tag_test.rb b/test/integration/tags/for_tag_test.rb index 23752bb..968ba5d 100644 --- a/test/integration/tags/for_tag_test.rb +++ b/test/integration/tags/for_tag_test.rb @@ -388,4 +388,14 @@ HERE assert_template_result(expected, template, loader_assigns) assert_template_result(expected, template, array_assigns) end + + def test_for_cleans_up_registers + context = Context.new(ErrorDrop.new) + + assert_raises(StandardError) do + Liquid::Template.parse('{% for i in (1..2) %}{{ standard_error }}{% endfor %}').render!(context) + end + + assert context.registers[:for_stack].empty? + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 32f8204..3c27113 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -88,3 +88,22 @@ class ThingWithToLiquid 'foobar' end end + +class ErrorDrop < Liquid::Drop + def standard_error + raise Liquid::StandardError, 'standard error' + end + + def argument_error + raise Liquid::ArgumentError, 'argument error' + end + + def syntax_error + raise Liquid::SyntaxError, 'syntax error' + end + + def exception + raise Exception, 'exception' + end +end +