From a4dc9ef9accb042b2829373e6c0e670ba2fa49ba Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Fri, 28 Jun 2019 14:10:25 +0530 Subject: [PATCH 1/2] Use private constant to test broken libxml version --- lib/nokogiri/xml/node.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/nokogiri/xml/node.rb b/lib/nokogiri/xml/node.rb index 2e701a4d4f7..8fbc5ba39bb 100644 --- a/lib/nokogiri/xml/node.rb +++ b/lib/nokogiri/xml/node.rb @@ -847,9 +847,12 @@ def add_sibling next_or_previous, node_or_tags node_or_tags end + IS_BROKEN_LIBXML_VERSION = LIBXML_VERSION.start_with?('2.6').freeze + private_constant :IS_BROKEN_LIBXML_VERSION + def to_format save_option, options # FIXME: this is a hack around broken libxml versions - return dump_html if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1] + return dump_html if Nokogiri.uses_libxml? && IS_BROKEN_LIBXML_VERSION options[:save_with] = save_option unless options[:save_with] serialize(options) @@ -857,7 +860,7 @@ def to_format save_option, options def write_format_to save_option, io, options # FIXME: this is a hack around broken libxml versions - return (io << dump_html) if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1] + return (io << dump_html) if Nokogiri.uses_libxml? && IS_BROKEN_LIBXML_VERSION options[:save_with] ||= save_option write_to io, options From 5558d1382f395ae958e4dfd1377b7c7c39e4b4fd Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sat, 29 Jun 2019 18:40:35 +0530 Subject: [PATCH 2/2] Check LIBXML_VERSION only if it is defined --- lib/nokogiri/xml/node.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nokogiri/xml/node.rb b/lib/nokogiri/xml/node.rb index 8fbc5ba39bb..1780c6ceca7 100644 --- a/lib/nokogiri/xml/node.rb +++ b/lib/nokogiri/xml/node.rb @@ -847,7 +847,7 @@ def add_sibling next_or_previous, node_or_tags node_or_tags end - IS_BROKEN_LIBXML_VERSION = LIBXML_VERSION.start_with?('2.6').freeze + IS_BROKEN_LIBXML_VERSION = defined?(LIBXML_VERSION) && LIBXML_VERSION.start_with?('2.6').freeze private_constant :IS_BROKEN_LIBXML_VERSION def to_format save_option, options