Compare commits

..
Author SHA1 Message Date
Dominic Petrick d6e07f9e5f pretend we're on 3.4 2025-01-15 11:17:05 +01:00
Ian Ker-Seymer 8c89e6a0dd Implement logic for stringify Hashes to keep compat with 3.4 2025-01-14 18:27:54 -05:00
Dominic Petrick c2530b233b Exploring 2025-01-14 19:37:19 +01:00
4 changed files with 22 additions and 50 deletions
+1 -1
View File
@@ -1 +1 @@
3.4.1
3.3.6
+20 -31
View File
@@ -90,41 +90,37 @@ module Liquid
obj
end
def self.to_s(obj, seen = {})
case obj
when Hash
# If the custom hash implementation overrides `#to_s`, use their
# custom implementation. Otherwise we use Liquid's default
# implementation.
if obj.class.instance_method(:to_s) == HASH_TO_S_METHOD
# if RUBY_VERSION >= '3.4'
def self.to_s(obj, seen = {})
case obj
when Hash
hash_inspect(obj, seen)
when Array
array_inspect(obj, seen)
else
obj.to_s
end
when Array
array_inspect(obj, seen)
else
obj.to_s
end
end
def self.inspect(obj, seen = {})
case obj
when Hash
# If the custom hash implementation overrides `#inspect`, use their
# custom implementation. Otherwise we use Liquid's default
# implementation.
if obj.class.instance_method(:inspect) == HASH_INSPECT_METHOD
def self.inspect(obj, seen = {})
case obj
when Hash
hash_inspect(obj, seen)
when Array
array_inspect(obj, seen)
else
obj.inspect
end
when Array
array_inspect(obj, seen)
else
obj.inspect
end
end
# else
# def self.to_s(obj, seen = nil)
# obj.to_s
# end
# def self.inspect(obj, seen = nil)
# obj.inspect
# end
# end
def self.array_inspect(arr, seen = {})
if seen[arr.object_id]
@@ -143,7 +139,6 @@ module Liquid
item_str = inspect(arr[cursor], seen)
str << item_str
cursor += 1
end
str << "]"
@@ -179,11 +174,5 @@ module Liquid
ensure
seen.delete(hash.object_id)
end
HASH_TO_S_METHOD = Hash.instance_method(:to_s)
private_constant :HASH_TO_S_METHOD
HASH_INSPECT_METHOD = Hash.instance_method(:inspect)
private_constant :HASH_INSPECT_METHOD
end
end
+1 -1
View File
@@ -2,5 +2,5 @@
# frozen_string_literal: true
module Liquid
VERSION = "5.6.5"
VERSION = "5.6.4"
end
-17
View File
@@ -80,21 +80,4 @@ class HashRenderingTest < Minitest::Test
def test_render_hash_with_hash_key
assert_template_result("{{\"foo\"=>\"bar\"}=>42}", "{{ my_hash }}", { "my_hash" => { Hash["foo" => "bar"] => 42 } })
end
def test_rendering_hash_with_custom_to_s_method_uses_custom_to_s
my_hash = Class.new(Hash) do
def to_s
"kewl"
end
end.new
assert_template_result("kewl", "{{ my_hash }}", { "my_hash" => my_hash })
end
def test_rendering_hash_without_custom_to_s_uses_default_inspect
my_hash = Class.new(Hash).new
my_hash[:foo] = :bar
assert_template_result("{:foo=>:bar}", "{{ my_hash }}", { "my_hash" => my_hash })
end
end