From 250048717cc91e090d8838b8f8d707e159ddaee3 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Thu, 11 Apr 2019 13:55:24 +0100 Subject: [PATCH] dunnololtest --- lib/liquid/context.rb | 3 ++- test/integration/tags/for_tag_test.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 1cf1885..cc25b42 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -143,7 +143,8 @@ module Liquid # Fetches an object starting at the local scope and then moving up the hierachy def find_variable(key, raise_on_not_found: true) - scope = @scope if @scope.key?(key) + value = @scope[key] + scope = @scope if value != nil if scope.nil? index = @environments.find_index do |e| diff --git a/test/integration/tags/for_tag_test.rb b/test/integration/tags/for_tag_test.rb index 9980e25..a74ab99 100644 --- a/test/integration/tags/for_tag_test.rb +++ b/test/integration/tags/for_tag_test.rb @@ -368,6 +368,23 @@ HERE assert_template_result(expected, template, assigns) end + def test_overwriting_internal_variable + template = <<-END_TEMPLATE + {% assign forloop = 'first' %} + + {% for item in items %} + {{ forloop }} + {% assign forloop = 'second' %} + {{ forloop }} + {% endfor %} + + {{ forloop }} + END_TEMPLATE + + result = Liquid::Template.parse(template).render('items' => '1') + assert_equal 'Liquid::ForloopDrop Liquid::ForloopDrop second', result.split.map(&:strip).join(' ') + end + class LoaderDrop < Liquid::Drop attr_accessor :each_called, :load_slice_called