Skip to content

Commit

Permalink
fix: HTML4::Document.to_xhtml self-closing tags
Browse files Browse the repository at this point in the history
Commit 1d06b4f introduced NO_EMPTY_TAGS into
SaveOptions::DEFAULT_XHTML which libxml2 ignored due to a
long-standing bug in serialization.

libxml2 v2.9.11 fixed that serialization bug
(https://gitlab.gnome.org/GNOME/libxml2/-/commit/dc6f009) and started
paying attention to the NO_EMPTY_TAGS save option, resulting in seeing
output containing, e.g. `<col></col>` instead of `<col/>`.

This commit updates the default XHTML save options to drop the
NO_EMPTY_TAGS flag, restoring this behavior.

Closes #2324
  • Loading branch information
flavorjones committed Sep 23, 2021
1 parent c4a9de4 commit 7376cbd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/nokogiri/xml/node/save_options.rb
Expand Up @@ -34,7 +34,7 @@ class SaveOptions
DEFAULT_HTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
end
# the default for XHTML document
DEFAULT_XHTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_XHTML
DEFAULT_XHTML = FORMAT | NO_DECLARATION | AS_XHTML

# Integer representation of the SaveOptions
attr_reader :options
Expand Down
9 changes: 9 additions & 0 deletions test/html4/test_document.rb
Expand Up @@ -372,6 +372,15 @@ def test_to_xhtml
assert_match("UTF-8", html.to_xhtml(encoding: "UTF-8"))
end

def test_to_xhtml_self_closing_tags
# https://github.com/sparklemotion/nokogiri/issues/2324
html = "<html><body><br><table><colgroup><col>"
doc = Nokogiri::HTML::Document.parse(html)
xhtml = doc.to_xhtml
assert_match(%r(<br ?/>), xhtml)
assert_match(%r(<col ?/>), xhtml)
end

def test_no_xml_header
html = Nokogiri::HTML(<<~EOHTML)
<html>
Expand Down

0 comments on commit 7376cbd

Please sign in to comment.