From df53bc250bf84ba91b598055df0e3f9fc75ec2eb Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Thu, 16 Jan 2025 11:35:34 -0500 Subject: [PATCH] Ensure we use `InputIterator#each` when in `join` filter --- lib/liquid/standardfilters.rb | 2 +- test/integration/standard_filter_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index a18b986f5..9da58e062 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -1065,7 +1065,7 @@ def initialize(input, context) def join(glue) first = true output = +"" - @input.each do |item| + each do |item| if first first = false else diff --git a/test/integration/standard_filter_test.rb b/test/integration/standard_filter_test.rb index e4eb3bec6..ce2a2841b 100644 --- a/test/integration/standard_filter_test.rb +++ b/test/integration/standard_filter_test.rb @@ -305,6 +305,16 @@ def test_join assert_equal('1121314', @filters.join([1, 2, 3, 4], 1)) end + def test_join_calls_to_liquid_on_each_element + drop = Class.new(Liquid::Drop) do + def to_liquid + 'i did it' + end + end + + assert_equal('i did it, i did it', @filters.join([drop.new, drop.new], ", ")) + end + def test_sort assert_equal([1, 2, 3, 4], @filters.sort([4, 3, 2, 1])) assert_equal([{ "a" => 1 }, { "a" => 2 }, { "a" => 3 }, { "a" => 4 }], @filters.sort([{ "a" => 4 }, { "a" => 3 }, { "a" => 1 }, { "a" => 2 }], "a"))