Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dep: update minimum supported version of libxml to 2.7.7 #3232

Merged
merged 8 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Nokogiri follows [Semantic Versioning](https://semver.org/), please see the [REA

### Dependencies

* [CRuby] Vendored libxml2 is updated to [v2.13.0](https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.13.0). @flavorjones
* [CRuby] Vendored libxslt is updated to [v1.1.40](https://gitlab.gnome.org/GNOME/libxslt/-/releases/v1.1.40). @flavorjones
* [CRuby] Vendored libxml2 is updated to [v2.13.0](https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.13.0). [#3230] @flavorjones
* [CRuby] Vendored libxslt is updated to [v1.1.40](https://gitlab.gnome.org/GNOME/libxslt/-/releases/v1.1.40). [#3230] @flavorjones
* [CRuby] Minimum supported version of libxml2 raised to v2.7.7 (released 2010-03-15) from v2.6.21. @flavorjones


### Added
Expand Down
8 changes: 1 addition & 7 deletions ext/nokogiri/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# helpful constants
PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
REQUIRED_LIBXML_VERSION = "2.6.21"
REQUIRED_LIBXML_VERSION = "2.7.7"
RECOMMENDED_LIBXML_VERSION = "2.9.3"

REQUIRED_MINI_PORTILE_VERSION = "~> 2.8.2" # keep this version in sync with the one in the gemspec
Expand Down Expand Up @@ -1116,12 +1116,6 @@ def compile
ensure_func("gumbo_parse_with_options", "nokogiri_gumbo.h")
end

have_func("xmlHasFeature") || abort("xmlHasFeature() is missing.") # introduced in libxml 2.6.21
have_func("xmlFirstElementChild") # introduced in libxml 2.7.3
have_func("xmlRelaxNGSetParserStructuredErrors") # introduced in libxml 2.6.24
have_func("xmlRelaxNGSetValidStructuredErrors") # introduced in libxml 2.6.21
have_func("xmlSchemaSetValidStructuredErrors") # introduced in libxml 2.6.23
have_func("xmlSchemaSetParserStructuredErrors") # introduced in libxml 2.6.23
have_func("rb_category_warning") # introduced in Ruby 3.0

other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k, v| [k, v].join(":") }.join(",")
Expand Down
121 changes: 0 additions & 121 deletions ext/nokogiri/libxml2_backwards_compat.c

This file was deleted.

7 changes: 0 additions & 7 deletions ext/nokogiri/nokogiri.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@

#include <libexslt/exslt.h>

/* libxml2_backwards_compat.c */
#ifndef HAVE_XMLFIRSTELEMENTCHILD
xmlNodePtr xmlFirstElementChild(xmlNodePtr parent);
xmlNodePtr xmlNextElementSibling(xmlNodePtr node);
xmlNodePtr xmlLastElementChild(xmlNodePtr parent);
#endif

#define XMLNS_PREFIX "xmlns"
#define XMLNS_PREFIX_LEN 6 /* including either colon or \0 */

Expand Down
24 changes: 2 additions & 22 deletions ext/nokogiri/xml_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,17 +1066,10 @@ previous_element(VALUE self)
xmlNodePtr node, sibling;
Noko_Node_Get_Struct(self, xmlNode, node);

/*
* note that we don't use xmlPreviousElementSibling here because it's buggy pre-2.7.7.
*/
sibling = node->prev;
sibling = xmlPreviousElementSibling(node);
if (!sibling) { return Qnil; }

while (sibling && sibling->type != XML_ELEMENT_NODE) {
sibling = sibling->prev;
}

return sibling ? noko_xml_node_wrap(Qnil, sibling) : Qnil ;
return noko_xml_node_wrap(Qnil, sibling);
}

/* :nodoc: */
Expand Down Expand Up @@ -2165,15 +2158,6 @@ in_context(VALUE self, VALUE _str, VALUE _options)

xmlSetStructuredErrorFunc((void *)err, Nokogiri_error_array_pusher);

/* Twiddle global variable because of a bug in libxml2.
* http://git.gnome.org/browse/libxml2/commit/?id=e20fb5a72c83cbfc8e4a8aa3943c6be8febadab7
*
* TODO: this is fixed, and HTML_PARSE_NOIMPLIED is defined, in libxml2 2.7.7
*/
#ifndef HTML_PARSE_NOIMPLIED
htmlHandleOmittedElem(0);
#endif

/* This function adds a fake node to the child of +node+. If the parser
* does not exit cleanly with XML_ERR_OK, the list is freed. This can
* leave the child pointers in a bad state if they were originally empty.
Expand Down Expand Up @@ -2202,10 +2186,6 @@ in_context(VALUE self, VALUE _str, VALUE _options)
child_iter = child_iter->next;
}

#ifndef HTML_PARSE_NOIMPLIED
htmlHandleOmittedElem(1);
#endif

xmlSetStructuredErrorFunc(NULL, NULL);

/*
Expand Down
4 changes: 0 additions & 4 deletions ext/nokogiri/xml_relax_ng.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ validate_document(VALUE self, VALUE document)
rb_raise(rb_eRuntimeError, "Could not create a validation context");
}

#ifdef HAVE_XMLRELAXNGSETVALIDSTRUCTUREDERRORS
xmlRelaxNGSetValidStructuredErrors(
valid_ctxt,
Nokogiri_error_array_pusher,
(void *)errors
);
#endif

xmlRelaxNGValidateDoc(valid_ctxt, doc);

Expand Down Expand Up @@ -79,13 +77,11 @@ xml_relax_ng_parse_schema(
rb_errors = rb_ary_new();
xmlSetStructuredErrorFunc((void *)rb_errors, Nokogiri_error_array_pusher);

#ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
xmlRelaxNGSetParserStructuredErrors(
c_parser_context,
Nokogiri_error_array_pusher,
(void *)rb_errors
);
#endif

c_schema = xmlRelaxNGParse(c_parser_context);

Expand Down
6 changes: 0 additions & 6 deletions ext/nokogiri/xml_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ validate_document(VALUE self, VALUE document)
rb_raise(rb_eRuntimeError, "Could not create a validation context");
}

#ifdef HAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS
xmlSchemaSetValidStructuredErrors(
valid_ctxt,
Nokogiri_error_array_pusher,
(void *)errors
);
#endif

xmlSchemaValidateDoc(valid_ctxt, doc);

Expand Down Expand Up @@ -84,13 +82,11 @@ validate_file(VALUE self, VALUE rb_filename)
rb_raise(rb_eRuntimeError, "Could not create a validation context");
}

#ifdef HAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS
xmlSchemaSetValidStructuredErrors(
valid_ctxt,
Nokogiri_error_array_pusher,
(void *)errors
);
#endif

xmlSchemaValidateFile(valid_ctxt, filename, 0);

Expand Down Expand Up @@ -122,13 +118,11 @@ xml_schema_parse_schema(
rb_errors = rb_ary_new();
xmlSetStructuredErrorFunc((void *)rb_errors, Nokogiri_error_array_pusher);

#ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
xmlSchemaSetParserStructuredErrors(
c_parser_context,
Nokogiri_error_array_pusher,
(void *)rb_errors
);
#endif

parse_options_int = (int)NUM2INT(rb_funcall(rb_parse_options, rb_intern("to_i"), 0));
if (parse_options_int & XML_PARSE_NONET) {
Expand Down
7 changes: 0 additions & 7 deletions lib/nokogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1577,19 +1577,12 @@ def add_sibling(next_or_previous, node_or_tags)
node_or_tags
end

USING_LIBXML_WITH_BROKEN_SERIALIZATION = Nokogiri.uses_libxml?("~> 2.6.0").freeze
private_constant :USING_LIBXML_WITH_BROKEN_SERIALIZATION

def to_format(save_option, options)
return dump_html if USING_LIBXML_WITH_BROKEN_SERIALIZATION

options[:save_with] = save_option unless options[:save_with]
serialize(options)
end

def write_format_to(save_option, io, options)
return (io << dump_html) if USING_LIBXML_WITH_BROKEN_SERIALIZATION

options[:save_with] ||= save_option
write_to(io, options)
end
Expand Down
1 change: 0 additions & 1 deletion nokogiri.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ Gem::Specification.new do |spec|
"ext/nokogiri/html4_entity_lookup.c",
"ext/nokogiri/html4_sax_parser_context.c",
"ext/nokogiri/html4_sax_push_parser.c",
"ext/nokogiri/libxml2_backwards_compat.c",
"ext/nokogiri/nokogiri.c",
"ext/nokogiri/nokogiri.h",
"ext/nokogiri/xml_attr.c",
Expand Down
6 changes: 1 addition & 5 deletions test/html4/sax/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ def test_parser_attributes

assert(block_called)

noshade_value = if Nokogiri.uses_libxml?("< 2.7.7")
["noshade", "noshade"]
else
["noshade", nil]
end
noshade_value = ["noshade", nil]

assert_equal(
[
Expand Down
2 changes: 0 additions & 2 deletions test/html4/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,12 @@ def test_empty_string_returns_empty_doc
end

def test_to_xhtml_with_indent
skip if Nokogiri.uses_libxml?("~> 2.6.0")
doc = Nokogiri::HTML4("<html><body><a>foo</a></body></html>")
doc = Nokogiri::HTML4(doc.to_xhtml(indent: 2))
assert_indent(2, doc)
end

def test_write_to_xhtml_with_indent
skip if Nokogiri.uses_libxml?("~> 2.6.0")
io = StringIO.new
doc = Nokogiri::HTML4("<html><body><a>foo</a></body></html>")
doc.write_xhtml_to(io, indent: 5)
Expand Down
14 changes: 2 additions & 12 deletions test/html4/test_document_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ def test_html_fragment
def test_html_fragment_has_outer_text
doc = "a<div>b</div>c"
fragment = Nokogiri::HTML4::Document.new.fragment(doc)
if Nokogiri.uses_libxml?("<= 2.6.16")
assert_equal("a<div>b</div><p>c</p>", fragment.to_s)
else
assert_equal("a<div>b</div>c", fragment.to_s)
end
assert_equal("a<div>b</div>c", fragment.to_s)
end

def test_html_fragment_case_insensitivity
Expand Down Expand Up @@ -162,13 +158,7 @@ def test_to_html
def test_to_xhtml
doc = "<span>foo<br></span><span>bar</span><p></p>"
fragment = Nokogiri::HTML4::Document.new.fragment(doc)
if Nokogiri.jruby? || Nokogiri.uses_libxml?(">= 2.7.0")
assert_equal("<span>foo<br /></span><span>bar</span><p></p>", fragment.to_xhtml)
else
# FIXME: why are we doing this ? this violates the spec,
# see http://www.w3.org/TR/xhtml1/#C_2
assert_equal("<span>foo<br></span><span>bar</span><p></p>", fragment.to_xhtml)
end
assert_equal("<span>foo<br /></span><span>bar</span><p></p>", fragment.to_xhtml)
end

def test_to_xml
Expand Down
4 changes: 1 addition & 3 deletions test/html4/test_element_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ def test_description

def test_subelements
sub_elements = ElementDescription["body"].sub_elements
if Nokogiri.uses_libxml?(">= 2.7.7")
if Nokogiri.uses_libxml?
assert_equal(65, sub_elements.length)
elsif Nokogiri.uses_libxml?
assert_equal(61, sub_elements.length)
else
assert_equal(105, sub_elements.length)
end
Expand Down
8 changes: 3 additions & 5 deletions test/xml/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,9 @@ def test_write_xml_to_with_indent
assert_indent(5, doc)
end

unless Nokogiri.uses_libxml?("~> 2.6.0")
def test_encoding
xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE, "UTF-8")
assert_equal("UTF-8", xml.encoding)
end
def test_encoding
xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE, "UTF-8")
assert_equal("UTF-8", xml.encoding)
end

def test_memory_explosion_on_invalid_xml
Expand Down
Loading