Skip to content

Commit 0ec52a4

Browse files
authored
Use Liquid::Utils.to_s for join filter (#1897)
1 parent 74af735 commit 0ec52a4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/liquid/standardfilters.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,18 @@ def initialize(input, context)
10631063
end
10641064

10651065
def join(glue)
1066-
to_a.join(glue.to_s)
1066+
first = true
1067+
output = +""
1068+
@input.each do |item|
1069+
if first
1070+
first = false
1071+
else
1072+
output << glue
1073+
end
1074+
1075+
output << Liquid::Utils.to_s(item)
1076+
end
1077+
output
10671078
end
10681079

10691080
def concat(args)

test/integration/hash_rendering_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def test_render_hash_with_array_values_hash
7777
assert_template_result("{\"numbers\"=>[{:foo=>42}]}", "{{ my_hash }}", { "my_hash" => { "numbers" => [{ foo: 42 }] } })
7878
end
7979

80+
def test_join_filter_with_hash
81+
array = [{ "key1" => "value1" }, { "key2" => "value2" }]
82+
glue = { "lol" => "wut" }
83+
assert_template_result("{\"key1\"=>\"value1\"}{\"lol\"=>\"wut\"}{\"key2\"=>\"value2\"}", "{{ my_array | join: glue }}", { "my_array" => array, "glue" => glue })
84+
end
85+
8086
def test_render_hash_with_hash_key
8187
assert_template_result("{{\"foo\"=>\"bar\"}=>42}", "{{ my_hash }}", { "my_hash" => { Hash["foo" => "bar"] => 42 } })
8288
end

0 commit comments

Comments
 (0)