From fc95575233f19632ca359b690a011721a460dbd1 Mon Sep 17 00:00:00 2001 From: lyn1dev <78355114+lyn1dev@users.noreply.github.com> Date: Thu, 26 Nov 2026 07:08:39 +0100 Subject: [PATCH] Rescue JSON::ParserError in object_address_for --- lib/super_diff/core/helpers.rb | 8 +++++++- spec/unit/core/helpers_spec.rb | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/super_diff/core/helpers.rb b/lib/super_diff/core/helpers.rb index 9be12efa..f5a5311d 100644 --- a/lib/super_diff/core/helpers.rb +++ b/lib/super_diff/core/helpers.rb @@ -60,7 +60,13 @@ def object_address_for(object) def object_address_for(object) # Sources: and json = JSON.parse(ObjectSpace.dump(object)) - json.is_a?(Hash) ? '0x%016x' % Integer(json['address'], 16) : '' + if json.is_a?(Hash) && json['address'] + '0x%016x' % Integer(json['address'], 16) + else + '' + end + rescue JSON::ParserError + '' end else def object_address_for(object) diff --git a/spec/unit/core/helpers_spec.rb b/spec/unit/core/helpers_spec.rb index 8d606a59..9f342d76 100644 --- a/spec/unit/core/helpers_spec.rb +++ b/spec/unit/core/helpers_spec.rb @@ -39,6 +39,15 @@ expect(helper.object_address_for(1.0)).to eq('') end + it 'returns an empty string for large Floats whose ObjectSpace.dump is invalid JSON' do + expect(helper.object_address_for(100_000.1)).to eq('') + expect(helper.object_address_for(-100_000.1)).to eq('') + end + + it 'returns an empty string for Symbols' do + expect(helper.object_address_for(:sym)).to eq('') + end + it 'returns an object address for Objects' do object = Object.new address = JSON.parse(ObjectSpace.dump(object))['address']