Skip to content

Commit 1f53682

Browse files
committed
feat: remove whitespace from pact content when saving to database
Closes: pact-foundation#260
1 parent 40be97d commit 1f53682

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/pact_broker/pacts/pact_params.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def self.from_path_info path_info
2323
def self.from_request request, path_info
2424
json_content = request.body.to_s
2525
parsed_content = begin
26-
JSON.parse(json_content, PACT_PARSING_OPTIONS)
26+
parsed = JSON.parse(json_content, PACT_PARSING_OPTIONS)
27+
json_content = parsed.to_json # remove whitespace
28+
parsed
2729
rescue
2830
{}
2931
end

spec/lib/pact_broker/pacts/pact_params_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ module Pacts
6767
end
6868

6969
it "extracts the json_content" do
70-
expect(subject.json_content).to eq body
70+
expect(subject.json_content).to eq JSON.parse(body).to_json
71+
end
72+
73+
it "removes whitespace from the json_content" do
74+
expect(subject.json_content).to_not include "\n"
7175
end
7276

7377
it "extracts the consumer name from the pact" do

0 commit comments

Comments
 (0)