diff --git a/lib/nokogiri/xml/node.rb b/lib/nokogiri/xml/node.rb index 11caa37532..bf594c472c 100644 --- a/lib/nokogiri/xml/node.rb +++ b/lib/nokogiri/xml/node.rb @@ -392,6 +392,7 @@ def to_xml encoding = nil def to_xhtml encoding = nil serialize(encoding, SaveOptions::FORMAT | SaveOptions::NO_DECLARATION | + SaveOptions::NO_EMPTY_TAGS | SaveOptions::AS_XHTML) end @@ -409,6 +410,7 @@ def write_to io, encoding = nil, save_options = SaveOptions::FORMAT def write_html_to io, encoding = nil write_to io, encoding, SaveOptions::FORMAT | SaveOptions::NO_DECLARATION | + SaveOptions::NO_EMPTY_TAGS | SaveOptions::AS_HTML end @@ -417,6 +419,7 @@ def write_html_to io, encoding = nil def write_xhtml_to io, encoding = nil write_to io, encoding, SaveOptions::FORMAT | SaveOptions::NO_DECLARATION | + SaveOptions::NO_EMPTY_TAGS | SaveOptions::AS_XHTML end diff --git a/test/xml/test_node.rb b/test/xml/test_node.rb index b13b81cf96..cea828cb8a 100644 --- a/test/xml/test_node.rb +++ b/test/xml/test_node.rb @@ -19,13 +19,15 @@ def test_write_to def test_write_to_with_block called = false io = StringIO.new + conf = nil @xml.write_to io do |config| called = true + conf = config config.format.as_html.no_empty_tags end io.rewind assert called - assert_equal @xml.serialize(nil, 1 | 64 | 4), io.read + assert_equal @xml.serialize(nil, conf.options), io.read end %w{ xml html xhtml }.each do |type| @@ -33,18 +35,20 @@ def test_write_to_with_block io = StringIO.new assert @xml.send(:"write_#{type}_to", io) io.rewind - assert_equal @xml.send(:"to_#{type}"), io.read + assert_match @xml.send(:"to_#{type}"), io.read end end def test_serialize_with_block called = false + conf = nil string = @xml.serialize do |config| called = true + conf = config config.format.as_html.no_empty_tags end assert called - assert_equal @xml.serialize(nil, 1 | 64 | 4), string + assert_equal @xml.serialize(nil, conf.options), string end def test_values