Skip to content

Commit

Permalink
fix: add blank lines to empty hashs - json 2.8.x regression
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Nov 28, 2024
1 parent df97a7d commit 66910bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pact/matchers/unix_diff_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
json = add_blank_lines_in_empty_hashes json
add_comma_to_end_of_arrays json
rescue JSON::GeneratorError
comparable.to_s
Expand Down
6 changes: 6 additions & 0 deletions lib/pact/shared/jruby_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 66910bd

Please sign in to comment.