From 406e1e4ba234d9357eb57ee3c280ac4790dec140 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Thu, 28 Nov 2024 15:56:58 +0000 Subject: [PATCH] fix: add blank lines to empty hashs - json 2.8.x regression --- lib/pact/matchers/unix_diff_formatter.rb | 1 + lib/pact/shared/jruby_support.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/pact/matchers/unix_diff_formatter.rb b/lib/pact/matchers/unix_diff_formatter.rb index 1946b25..e7b1500 100644 --- a/lib/pact/matchers/unix_diff_formatter.rb +++ b/lib/pact/matchers/unix_diff_formatter.rb @@ -62,6 +62,7 @@ def generate_string diff, target begin # Can't think of an elegant way to check if we can pretty generate other than to try it and maybe fail json = fix_blank_lines_in_empty_hashes JSON.pretty_generate(comparable) + add_blank_lines_in_empty_hashes json add_comma_to_end_of_arrays json rescue JSON::GeneratorError comparable.to_s diff --git a/lib/pact/shared/jruby_support.rb b/lib/pact/shared/jruby_support.rb index 5f01032..d19f6b9 100644 --- a/lib/pact/shared/jruby_support.rb +++ b/lib/pact/shared/jruby_support.rb @@ -14,5 +14,11 @@ def fix_blank_lines_in_empty_hashes json json.gsub(/({\n)\n(\s*})/,'\1\2') end + # formatting changes when using json 2.8.x + # in ruby 3.x + + # brought in by faraday 2.12.0 + def add_blank_lines_in_empty_hashes(json) + json.gsub(/({\s*})/, "{\n }") + end end end \ No newline at end of file