From b08bcf00ac787771931ea91a92fc7a0a94221b55 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Thu, 3 Sep 2020 06:55:24 -0400 Subject: [PATCH] Push interrupts from Continue and Break tags rather than from BlockBody (#1286) --- lib/liquid/block_body.rb | 17 +++++------------ lib/liquid/tags/break.rb | 7 +++++-- lib/liquid/tags/continue.rb | 7 +++++-- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index 973450e4..985a492d 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -141,23 +141,16 @@ module Liquid while (node = @nodelist[idx]) previous_output_size = output.bytesize - case node - when String + if node.instance_of?(String) output << node - when Variable + elsif node.instance_of?(Variable) render_node(context, output, node) - when Block + else render_node(context, node.blank? ? +'' : output, node) - break if context.interrupt? # might have happened in a for-block - when Continue, Break # If we get an Interrupt that means the block must stop processing. An # Interrupt is any command that stops block execution such as {% break %} - # or {% continue %} - context.push_interrupt(node.interrupt) - break - else # Other non-Block tags - render_node(context, output, node) - break if context.interrupt? # might have happened through an include + # or {% continue %}. These tags may also occur through Block or Include tags. + break if context.interrupt? # might have happened in a for-block end idx += 1 diff --git a/lib/liquid/tags/break.rb b/lib/liquid/tags/break.rb index 80f46278..15b33dda 100644 --- a/lib/liquid/tags/break.rb +++ b/lib/liquid/tags/break.rb @@ -11,8 +11,11 @@ module Liquid # {% endfor %} # class Break < Tag - def interrupt - BreakInterrupt.new + INTERRUPT = BreakInterrupt.new.freeze + + def render_to_output_buffer(context, output) + context.push_interrupt(INTERRUPT) + output end end diff --git a/lib/liquid/tags/continue.rb b/lib/liquid/tags/continue.rb index fb1f371e..a70442f0 100644 --- a/lib/liquid/tags/continue.rb +++ b/lib/liquid/tags/continue.rb @@ -11,8 +11,11 @@ module Liquid # {% endfor %} # class Continue < Tag - def interrupt - ContinueInterrupt.new + INTERRUPT = ContinueInterrupt.new.freeze + + def render_to_output_buffer(context, output) + context.push_interrupt(INTERRUPT) + output end end