From d06a535ec3c704bee4bf46c197f2e76669feca50 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 29 Nov 2024 15:52:38 +0000 Subject: [PATCH] fix: add blank lines to empty hashs - json 2.8.x regression for pact-ruby --- lib/pact/shared/active_support_support.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/pact/shared/active_support_support.rb b/lib/pact/shared/active_support_support.rb index 2e4826b..40167d0 100644 --- a/lib/pact/shared/active_support_support.rb +++ b/lib/pact/shared/active_support_support.rb @@ -42,10 +42,11 @@ def fix_regexp regexp # Oh ActiveSupport, why.... def fix_json_formatting json if json =~ /\{".*?":"/ - JSON.pretty_generate(JSON.parse(json, create_additions: false)) + json = JSON.pretty_generate(JSON.parse(json, create_additions: false)) else json end + fix_empty_hash_and_array json end def remove_unicode json @@ -61,5 +62,13 @@ def warn_about_regexp(thing) end end end + + private + + def fix_empty_hash_and_array json + json = json.gsub(/({\s*})/, "{\n }") + json.gsub(/\[\s*\]/, "[\n ]") + json + end end end