Skip to content

Commit d31ed25

Browse files
lluisdescala
andauthored
Fix exception when soap:Fault contains invalid encoding (#923)
Co-authored-by: David Escala <[email protected]>
1 parent 87e87eb commit d31ed25

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

lib/savon/soap_fault.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ module Savon
33
class SOAPFault < Error
44

55
def self.present?(http, xml = nil)
6-
xml ||= http.body
6+
xml_orig ||= http.body
7+
if xml_orig.valid_encoding?
8+
xml = xml_orig
9+
else
10+
xml = xml_orig.encode(
11+
'UTF-8', "ISO-8859-1", invalid: :replace, undef: :replace, replace: ''
12+
)
13+
end
714
fault_node = xml.include?("Fault>")
815
soap1_fault = xml.match(/faultcode\/?>/) && xml.match(/faultstring\/?>/)
916
soap2_fault = xml.include?("Code>") && xml.include?("Reason>")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
2+
<soap:Body>
3+
<soap:Fault>
4+
<faultcode>soap:Server</faultcode>
5+
<faultstring>Response with invalid encoding ñ ñ</faultstring>
6+
</soap:Fault>
7+
</soap:Body>
8+
</soap:Envelope>

spec/savon/soap_fault_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
it "returns false unless the HTTP response contains a SOAP fault" do
5050
expect(Savon::SOAPFault.present? new_response).to be_falsey
5151
end
52+
53+
it "returns true if the HTTP response contains a SOAP fault with invalid ecoded char" do
54+
http = new_response(:body => Fixture.response(:soap_fault_invalid_encoding))
55+
expect(Savon::SOAPFault.present? http).to be_truthy
56+
end
5257
end
5358

5459
[:message, :to_s].each do |method|

0 commit comments

Comments
 (0)