From 69c45b857ca4168522942a59cb5d064fec230155 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Fri, 2 Aug 2024 17:22:58 +0200 Subject: [PATCH] Rescue exceptions --- lib/webmock/request_pattern.rb | 1 + spec/unit/request_pattern_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/webmock/request_pattern.rb b/lib/webmock/request_pattern.rb index 44c3f28b..124087ff 100644 --- a/lib/webmock/request_pattern.rb +++ b/lib/webmock/request_pattern.rb @@ -309,6 +309,7 @@ def body_as_hash(body, content_type) else WebMock::Util::QueryMapper.query_to_values(body, notation: Config.instance.query_values_notation) end + rescue Psych::SyntaxError, REXML::ParseException end def body_format(content_type) diff --git a/spec/unit/request_pattern_spec.rb b/spec/unit/request_pattern_spec.rb index f6fb2e51..8cfc89ac 100644 --- a/spec/unit/request_pattern_spec.rb +++ b/spec/unit/request_pattern_spec.rb @@ -562,7 +562,7 @@ def match(request_signature) it "should not match when body is not json" do expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)). not_to match(WebMock::RequestSignature.new(:post, "www.example.com", - headers: {content_type: content_type}, body: "foo bar")) + headers: {content_type: content_type}, body: "[foo bar")) end it "should not match if request body is different" do @@ -614,7 +614,7 @@ def match(request_signature) it "should not match when body is not xml" do expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)). not_to match(WebMock::RequestSignature.new(:post, "www.example.com", - headers: {content_type: content_type}, body: "foo bar")) + headers: {content_type: content_type}, body: "