From cec38af2c0ba6fd6805b7285bbe5b907fecb5547 Mon Sep 17 00:00:00 2001 From: Andy Anastasiadis-Gray Date: Wed, 16 Jan 2019 16:13:45 +1300 Subject: [PATCH 1/2] Squash bug when nodes are visited coerced more then once in a request --- lib/contentful/coercions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/contentful/coercions.rb b/lib/contentful/coercions.rb index 556f539..1254bad 100644 --- a/lib/contentful/coercions.rb +++ b/lib/contentful/coercions.rb @@ -150,7 +150,7 @@ def coerce_block(block, configuration) def coerce_link(node, configuration) return node unless node.key?('data') && node['data'].key?('target') - return node unless node['data']['target']['sys']['type'] == 'Link' + return node unless node['data']['target'].is_a?(Hash) && node['data']['target']['sys']['type'] == 'Link' return nil if Support.unresolvable?(node['data']['target'], configuration[:errors]) From e8782ae0f21bd1e260e6a0c746d1f7990f87adbc Mon Sep 17 00:00:00 2001 From: Andy Anastasiadis-Gray Date: Thu, 17 Jan 2019 08:01:35 +1300 Subject: [PATCH 2/2] return the target if this node has already been coerced --- lib/contentful/coercions.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/contentful/coercions.rb b/lib/contentful/coercions.rb index 1254bad..6c40b05 100644 --- a/lib/contentful/coercions.rb +++ b/lib/contentful/coercions.rb @@ -150,7 +150,8 @@ def coerce_block(block, configuration) def coerce_link(node, configuration) return node unless node.key?('data') && node['data'].key?('target') - return node unless node['data']['target'].is_a?(Hash) && node['data']['target']['sys']['type'] == 'Link' + return node['data']['target'] unless node['data']['target'].is_a?(Hash) + return node unless node['data']['target']['sys']['type'] == 'Link' return nil if Support.unresolvable?(node['data']['target'], configuration[:errors])