From c42ba386cf984665876c4987902ca73dcdf07667 Mon Sep 17 00:00:00 2001 From: Craig Blanchette Date: Tue, 16 Dec 2025 21:52:14 -0500 Subject: [PATCH 1/2] Check for key? instead of checking if a Hash --- lib/twig/extension/core.rb | 2 +- spec/lib/twig/extension/core_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/twig/extension/core.rb b/lib/twig/extension/core.rb index 6c83e3d..2fc9b5f 100644 --- a/lib/twig/extension/core.rb +++ b/lib/twig/extension/core.rb @@ -869,7 +869,7 @@ def self.get_attribute( if object.respond_to?(:[]) && ( (object.is_a?(Array) && attribute.is_a?(Integer) && attribute < object.length) || ( - object.is_a?(Hash) && ( + object.respond_to?(:key?) && ( object.key?(attribute) || (attribute.respond_to?(:to_sym) && object.key?(attribute.to_sym)) || (attribute.respond_to?(:to_s) && object.key?(attribute.to_s)) diff --git a/spec/lib/twig/extension/core_spec.rb b/spec/lib/twig/extension/core_spec.rb index 9022f09..df31e59 100644 --- a/spec/lib/twig/extension/core_spec.rb +++ b/spec/lib/twig/extension/core_spec.rb @@ -504,5 +504,19 @@ def foo ) ).to eq(42) end + + it 'uses bracket access even when not a hash or array if doing an array call' do + object = Class.new(SimpleDelegator).new({ pi: 3.14 }) + + expect( + described_class.get_attribute( + environment, + instance_double(Twig::Source), + object, + :pi, + Twig::Template::METHOD_CALL + ) + ).to eq(3.14) + end end end From 2b2340960cd536f43e61d45b46d4bb282a391c97 Mon Sep 17 00:00:00 2001 From: Craig Blanchette Date: Tue, 16 Dec 2025 21:52:47 -0500 Subject: [PATCH 2/2] Bump version to 0.0.8 --- twig-ruby.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twig-ruby.gemspec b/twig-ruby.gemspec index 716b335..3788f76 100644 --- a/twig-ruby.gemspec +++ b/twig-ruby.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = 'twig_ruby' - s.version = '0.0.7' + s.version = '0.0.8' s.summary = 'Twig Templating for Ruby' s.description = '' s.authors = ['Craig Blanchette', 'Fabian Potencier']