Skip to content

Commit bafe8c7

Browse files
sunsationspcai
authored andcommitted
Logging: Use filter without automatic pretty printing (#757)
The filter functionality is using nokogiri to filter out unwanted elements. The default `.to_xml` of nokogiri automatically pretty prints the document, even if the pretty_print_xml option is set to false. This commit fixes this, by applying the filter and taking the `pretty_print_xml = false` into account. See http://stackoverflow.com/questions/8406251/nokogiri-to-xml-without-carriage-returns for details of using nokogiri without carriage returns.
1 parent 554837c commit bafe8c7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/savon/log_message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def apply_filter!(document, filter)
4545
end
4646

4747
def nokogiri_options
48-
@pretty_print ? { :indent => 2 } : {}
48+
@pretty_print ? { :indent => 2 } : { :save_with => Nokogiri::XML::Node::SaveOptions::AS_XML }
4949
end
5050

5151
end

spec/savon/log_message_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@
2121
expect(message).to include("\n <body>")
2222
end
2323

24-
it "filters tags in a given message" do
24+
it "filters tags in a given message without pretty printing" do
2525
message = log_message("<root><password>secret</password></root>", [:password], false).to_s
2626
expect(message).to include("<password>***FILTERED***</password>")
27+
expect(message).to_not include("\n <password>***FILTERED***</password>") # no pretty printing
28+
end
29+
30+
it "filters tags in a given message with pretty printing" do
31+
message = log_message("<root><password>secret</password></root>", [:password], true).to_s
32+
expect(message).to include("\n <password>***FILTERED***</password>")
2733
end
2834

2935
it "properly applies Proc filter" do

0 commit comments

Comments
 (0)