mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 07:05:12 -07:00
Use Liquid::Utils.to_s for join filter (#1897)
This commit is contained in:
@@ -1063,7 +1063,18 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def join(glue)
|
def join(glue)
|
||||||
to_a.join(glue.to_s)
|
first = true
|
||||||
|
output = +""
|
||||||
|
@input.each do |item|
|
||||||
|
if first
|
||||||
|
first = false
|
||||||
|
else
|
||||||
|
output << glue
|
||||||
|
end
|
||||||
|
|
||||||
|
output << Liquid::Utils.to_s(item)
|
||||||
|
end
|
||||||
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
def concat(args)
|
def concat(args)
|
||||||
|
|||||||
@@ -77,6 +77,12 @@ class HashRenderingTest < Minitest::Test
|
|||||||
assert_template_result("{\"numbers\"=>[{:foo=>42}]}", "{{ my_hash }}", { "my_hash" => { "numbers" => [{ foo: 42 }] } })
|
assert_template_result("{\"numbers\"=>[{:foo=>42}]}", "{{ my_hash }}", { "my_hash" => { "numbers" => [{ foo: 42 }] } })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_join_filter_with_hash
|
||||||
|
array = [{ "key1" => "value1" }, { "key2" => "value2" }]
|
||||||
|
glue = { "lol" => "wut" }
|
||||||
|
assert_template_result("{\"key1\"=>\"value1\"}{\"lol\"=>\"wut\"}{\"key2\"=>\"value2\"}", "{{ my_array | join: glue }}", { "my_array" => array, "glue" => glue })
|
||||||
|
end
|
||||||
|
|
||||||
def test_render_hash_with_hash_key
|
def test_render_hash_with_hash_key
|
||||||
assert_template_result("{{\"foo\"=>\"bar\"}=>42}", "{{ my_hash }}", { "my_hash" => { Hash["foo" => "bar"] => 42 } })
|
assert_template_result("{{\"foo\"=>\"bar\"}=>42}", "{{ my_hash }}", { "my_hash" => { Hash["foo" => "bar"] => 42 } })
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user