nokogiri 1.15.0 → 1.16.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +17 -14
  3. data/README.md +4 -1
  4. data/dependencies.yml +9 -8
  5. data/ext/nokogiri/extconf.rb +3 -4
  6. data/ext/nokogiri/html4_sax_push_parser.c +1 -1
  7. data/ext/nokogiri/nokogiri.h +10 -3
  8. data/ext/nokogiri/test_global_handlers.c +1 -1
  9. data/ext/nokogiri/xml_cdata.c +28 -23
  10. data/ext/nokogiri/xml_document.c +13 -5
  11. data/ext/nokogiri/xml_namespace.c +0 -4
  12. data/ext/nokogiri/xml_node.c +6 -9
  13. data/ext/nokogiri/xml_reader.c +25 -48
  14. data/ext/nokogiri/xml_relax_ng.c +1 -1
  15. data/ext/nokogiri/xml_sax_parser_context.c +4 -0
  16. data/ext/nokogiri/xml_sax_push_parser.c +1 -1
  17. data/ext/nokogiri/xml_schema.c +13 -8
  18. data/ext/nokogiri/xml_syntax_error.c +3 -3
  19. data/ext/nokogiri/xml_text.c +24 -19
  20. data/ext/nokogiri/xml_xpath_context.c +2 -5
  21. data/ext/nokogiri/xslt_stylesheet.c +8 -3
  22. data/gumbo-parser/Makefile +18 -0
  23. data/gumbo-parser/src/error.c +1 -1
  24. data/gumbo-parser/src/parser.c +8 -5
  25. data/gumbo-parser/src/tokenizer.c +1 -0
  26. data/lib/nokogiri/css/parser_extras.rb +1 -1
  27. data/lib/nokogiri/css/xpath_visitor.rb +1 -21
  28. data/lib/nokogiri/html4/document.rb +1 -1
  29. data/lib/nokogiri/html4/encoding_reader.rb +1 -1
  30. data/lib/nokogiri/html5.rb +0 -66
  31. data/lib/nokogiri/jruby/nokogiri_jars.rb +3 -3
  32. data/lib/nokogiri/version/constant.rb +1 -1
  33. data/lib/nokogiri/version/info.rb +6 -5
  34. data/lib/nokogiri/xml/attr.rb +2 -2
  35. data/lib/nokogiri/xml/document.rb +4 -5
  36. data/lib/nokogiri/xml/document_fragment.rb +2 -2
  37. data/lib/nokogiri/xml/namespace.rb +1 -2
  38. data/lib/nokogiri/xml/node.rb +31 -24
  39. data/lib/nokogiri/xml/node_set.rb +3 -3
  40. data/lib/nokogiri/xml/reader.rb +10 -9
  41. data/lib/nokogiri/xml/searchable.rb +3 -3
  42. data/lib/nokogiri/xml/syntax_error.rb +1 -1
  43. data/lib/nokogiri/xml.rb +1 -1
  44. data/lib/nokogiri/xslt/stylesheet.rb +29 -7
  45. data/lib/nokogiri/xslt.rb +1 -1
  46. data/lib/nokogiri.rb +1 -1
  47. data/ports/archives/libxml2-2.12.5.tar.xz +0 -0
  48. data/ports/archives/libxslt-1.1.39.tar.xz +0 -0
  49. metadata +6 -6
  50. data/ports/archives/libxml2-2.11.3.tar.xz +0 -0
  51. data/ports/archives/libxslt-1.1.38.tar.xz +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cad4c790fb66865a2b47c27345cdb2785c61b9a599490fcbef62150e83078547
4
- data.tar.gz: da81f866cd1451d0583b8fd376625185052c8d17f7a3b6250c43fec7d906daf8
3
+ metadata.gz: eff8843eb712576ae46f11395a29e0daf5b2b99fbec124a604c784281fab2f69
4
+ data.tar.gz: c4aa6b876e82af3b9d6620cda1040130e17e493d80e7dc84c6c7715d7783d1a1
5
5
  SHA512:
6
- metadata.gz: 5b7e4a97225c6a4516fc298a9826d890fd652d1adcd7a2b90e02979e46015114ba9f63d9fdd34b5d398b562a23745386c77ba90165f8e214354a149758b88bfa
7
- data.tar.gz: a7127084785dbd6761e87d14b57fe17fa338babba7a05e8f724bfeb749b7ce4344681bb9429eca6c9bc6defd27f6238d4c785a0657656a7d9ca7e531926d1423
6
+ metadata.gz: 350715c0687e8d463bc56b666f2113f21ec778998d4862ae88c13a6dbe5ab471ffff1c123870a5ceb9934b0e645ce9e01e25e9242c140244e234076a47cd1922
7
+ data.tar.gz: 5f617afb7c937a1f321d2f11c13995bd26a7344c9137a63198c88e56512f9cbb8d86d1cb4184cd67dbca70fa380fc2e35cbcd49e487bf73bde323312db547cff
data/Gemfile CHANGED
@@ -5,35 +5,38 @@ source "https://rubygems.org"
5
5
  gemspec
6
6
 
7
7
  group :development do
8
+ # ruby 3.4.0-dev removed some gems from the default set
9
+ #
10
+ # TODO: we should be able to remove these as our gem dependencies sort it out and we pull them in
11
+ # transitively.
12
+ gem "mutex_m"
13
+
8
14
  # bootstrapping
9
15
  gem "bundler", "~> 2.3"
10
- gem "rake", "= 13.0.6"
16
+ gem "rake", "13.1.0"
11
17
 
12
18
  # building extensions
13
- gem "rake-compiler", "= 1.2.1"
14
- gem "rake-compiler-dock", "= 1.3.0"
15
-
16
- # documentation
17
- gem "hoe-markdown", "= 1.4.0"
19
+ gem "rake-compiler", "1.2.6"
20
+ gem "rake-compiler-dock", "1.4.0"
18
21
 
19
22
  # parser generator
20
23
  gem "rexical", "= 1.0.7"
21
24
 
22
25
  # tests
23
- gem "minitest", "5.18.0"
24
- gem "minitest-reporters", "1.6.0"
25
- gem "ruby_memcheck", git: "https://github.com/flavorjones/ruby_memcheck", ref: "flavorjones-nokogiri-huge-parse-option"
26
+ gem "minitest", "5.21.2"
27
+ gem "minitest-parallel_fork", "2.0.0"
28
+ gem "ruby_memcheck", "2.3.0"
26
29
  gem "rubyzip", "~> 2.3.2"
27
30
  gem "simplecov", "= 0.21.2"
28
31
 
29
32
  # rubocop
30
33
  if Gem::Requirement.new("~> 3.0").satisfied_by?(Gem::Version.new(RUBY_VERSION))
31
- gem "rubocop", "1.50.2"
32
- gem "rubocop-minitest", "0.31.0"
34
+ gem "rubocop", "1.60.2"
35
+ gem "rubocop-minitest", "0.34.5"
33
36
  gem "rubocop-packaging", "0.5.2"
34
- gem "rubocop-performance", "1.17.1"
37
+ gem "rubocop-performance", "1.20.2"
35
38
  gem "rubocop-rake", "= 0.6.0"
36
- gem "rubocop-shopify", "2.13.0"
39
+ gem "rubocop-shopify", "2.14.0"
37
40
  end
38
41
  end
39
42
 
@@ -41,5 +44,5 @@ end
41
44
  # `bundle config set --local without rdoc`
42
45
  # Then re-run `bundle install`.
43
46
  group :rdoc do
44
- gem "rdoc", "6.5.0"
47
+ gem "rdoc", "6.6.2"
45
48
  end
data/README.md CHANGED
@@ -55,6 +55,7 @@ There are a few ways to ask exploratory questions:
55
55
 
56
56
  - The Nokogiri mailing list is active at https://groups.google.com/group/nokogiri-talk
57
57
  - Open an issue using the "Help Request" template at https://github.com/sparklemotion/nokogiri/issues
58
+ - Open a discussion at https://github.com/sparklemotion/nokogiri/discussions
58
59
 
59
60
  Please do not mail the maintainers at their personal addresses.
60
61
 
@@ -90,6 +91,8 @@ We bump `Major.Minor.Patch` versions following this guidance:
90
91
  - Updating packaged libraries for non-security-related reasons.
91
92
  - Dropping support for EOLed Ruby versions. [Some folks find this objectionable](https://github.com/sparklemotion/nokogiri/issues/1568), but [SemVer says this is OK if the public API hasn't changed](https://semver.org/#what-should-i-do-if-i-update-my-own-dependencies-without-changing-the-public-api).
92
93
  - Backwards-incompatible changes to internal or private methods and constants. These are detailed in the "Changes" section of each changelog entry.
94
+ - Removal of deprecated methods or parameters, after a generous transition period; usually when those methods or parameters are rarely-used or dangerous to the user. Essentially, removals that do not justify a major version bump.
95
+
93
96
 
94
97
  `Patch`:
95
98
 
@@ -111,7 +114,7 @@ You can help sponsor the maintainers of this software through one of these organ
111
114
 
112
115
  Requirements:
113
116
 
114
- - Ruby >= 2.7
117
+ - Ruby >= 3.0
115
118
  - JRuby >= 9.4.0.0
116
119
 
117
120
 
data/dependencies.yml CHANGED
@@ -1,16 +1,17 @@
1
+
1
2
  libxml2:
2
- version: "2.11.3"
3
- sha256: "f1acae1664bda006cd81bfc238238217043d586d06659d5c0e3d1bcebe040870"
4
- # sha-256 hash provided in https://download.gnome.org/sources/libxml2/2.11/libxml2-2.11.3.sha256sum
3
+ version: "2.12.5"
4
+ sha256: "a972796696afd38073e0f59c283c3a2f5a560b5268b4babc391b286166526b21"
5
+ # sha-256 hash provided in https://download.gnome.org/sources/libxml2/2.12/libxml2-2.12.5.sha256sum
5
6
 
6
7
  libxslt:
7
- version: "1.1.38"
8
- sha256: "1f32450425819a09acaff2ab7a5a7f8a2ec7956e505d7beeb45e843d0e1ecab1"
9
- # sha-256 hash provided in https://download.gnome.org/sources/libxslt/1.1/libxslt-1.1.38.sha256sum
8
+ version: "1.1.39"
9
+ sha256: "2a20ad621148339b0759c4d4e96719362dee64c9a096dbba625ba053846349f0"
10
+ # sha-256 hash provided in https://download.gnome.org/sources/libxslt/1.1/libxslt-1.1.39.sha256sum
10
11
 
11
12
  zlib:
12
- version: "1.2.13"
13
- sha256: "b3a24de97a8fdbc835b9833169501030b8977031bcb54b3b3ac13740f846ab30"
13
+ version: "1.3"
14
+ sha256: "ff0ba4c292013dbc27530b3a81e1f9a813cd39de01ca5e0f8bf355702efa593e"
14
15
  # SHA-256 hash provided on http://zlib.net/
15
16
 
16
17
  libiconv:
@@ -443,7 +443,7 @@ def process_recipe(name, version, static_p, cross_p, cacheable_p = true)
443
443
  # We use 'host' to set compiler prefix for cross-compiling. Prefer host_alias over host. And
444
444
  # prefer i686 (what external dev tools use) to i386 (what ruby's configure.ac emits).
445
445
  recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
446
- recipe.host = recipe.host.gsub(/i386/, "i686")
446
+ recipe.host = recipe.host.gsub("i386", "i686")
447
447
 
448
448
  recipe.target = File.join(PACKAGE_ROOT_DIR, "ports") if cacheable_p
449
449
  recipe.configure_options << "--libdir=#{File.join(recipe.path, "lib")}"
@@ -651,8 +651,7 @@ append_cppflags(ENV["CPPFLAGS"].split) unless ENV["CPPFLAGS"].nil?
651
651
  append_ldflags(ENV["LDFLAGS"].split) unless ENV["LDFLAGS"].nil?
652
652
  $LIBS = concat_flags($LIBS, ENV["LIBS"])
653
653
 
654
- # nokogumbo code uses C90/C99 features, let's make sure older compilers won't give
655
- # errors/warnings. see #2302
654
+ # libgumbo uses C90/C99 features, see #2302
656
655
  append_cflags(["-std=c99", "-Wno-declaration-after-statement"])
657
656
 
658
657
  # gumbo html5 serialization is slower with O3, let's make sure we use O2
@@ -919,6 +918,7 @@ else
919
918
  "--with-c14n",
920
919
  "--with-debug",
921
920
  "--with-threads",
921
+ "--without-tls", # see https://github.com/sparklemotion/nokogiri/issues/3031
922
922
  "CPPFLAGS=#{cppflags}",
923
923
  "CFLAGS=#{cflags}",
924
924
  ]
@@ -1087,7 +1087,6 @@ have_func("xmlRelaxNGSetParserStructuredErrors") # introduced in libxml 2.6.24
1087
1087
  have_func("xmlRelaxNGSetValidStructuredErrors") # introduced in libxml 2.6.21
1088
1088
  have_func("xmlSchemaSetValidStructuredErrors") # introduced in libxml 2.6.23
1089
1089
  have_func("xmlSchemaSetParserStructuredErrors") # introduced in libxml 2.6.23
1090
- have_func("rb_gc_location") # introduced in Ruby 2.7
1091
1090
  have_func("rb_category_warning") # introduced in Ruby 3.0
1092
1091
 
1093
1092
  other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k, v| [k, v].join(":") }.join(",")
@@ -32,7 +32,7 @@ native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
32
32
 
33
33
  if ((status != 0) && !(ctx->options & XML_PARSE_RECOVER)) {
34
34
  // TODO: there appear to be no tests for this block
35
- xmlErrorPtr e = xmlCtxtGetLastError(ctx);
35
+ xmlErrorConstPtr e = xmlCtxtGetLastError(ctx);
36
36
  Nokogiri_error_raise(NULL, e);
37
37
  }
38
38
 
@@ -66,6 +66,13 @@ xmlNodePtr xmlLastElementChild(xmlNodePtr parent);
66
66
  #define XMLNS_PREFIX "xmlns"
67
67
  #define XMLNS_PREFIX_LEN 6 /* including either colon or \0 */
68
68
 
69
+ #ifndef xmlErrorConstPtr
70
+ # if LIBXML_VERSION >= 21200
71
+ # define xmlErrorConstPtr const xmlError *
72
+ # else
73
+ # define xmlErrorConstPtr xmlError *
74
+ # endif
75
+ #endif
69
76
 
70
77
  #include <ruby.h>
71
78
  #include <ruby/st.h>
@@ -227,9 +234,9 @@ void Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *hand
227
234
  void Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state, void *user_data,
228
235
  xmlStructuredErrorFunc handler);
229
236
  void Nokogiri_structured_error_func_restore(libxmlStructuredErrorHandlerState *handler_state);
230
- VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error);
231
- void Nokogiri_error_array_pusher(void *ctx, xmlErrorPtr error);
232
- NORETURN_DECL void Nokogiri_error_raise(void *ctx, xmlErrorPtr error);
237
+ VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorConstPtr error);
238
+ void Nokogiri_error_array_pusher(void *ctx, xmlErrorConstPtr error);
239
+ NORETURN_DECL void Nokogiri_error_raise(void *ctx, xmlErrorConstPtr error);
233
240
  void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler,
234
241
  const char *function_name) ;
235
242
 
@@ -3,7 +3,7 @@
3
3
  static VALUE foreign_error_handler_block = Qnil;
4
4
 
5
5
  static void
6
- foreign_error_handler(void *user_data, xmlErrorPtr c_error)
6
+ foreign_error_handler(void *user_data, xmlErrorConstPtr c_error)
7
7
  {
8
8
  rb_funcall(foreign_error_handler_block, rb_intern("call"), 0);
9
9
  }
@@ -12,39 +12,44 @@ VALUE cNokogiriXmlCData;
12
12
  * raise a TypeError exception.
13
13
  */
14
14
  static VALUE
15
- new (int argc, VALUE *argv, VALUE klass)
15
+ rb_xml_cdata_s_new(int argc, VALUE *argv, VALUE klass)
16
16
  {
17
- xmlDocPtr xml_doc;
18
- xmlNodePtr node;
19
- VALUE doc;
20
- VALUE content;
21
- VALUE rest;
17
+ xmlDocPtr c_document;
18
+ xmlNodePtr c_node;
19
+ VALUE rb_document;
20
+ VALUE rb_content;
21
+ VALUE rb_rest;
22
22
  VALUE rb_node;
23
- xmlChar *content_str = NULL;
24
- int content_str_len = 0;
23
+ xmlChar *c_content = NULL;
24
+ int c_content_len = 0;
25
25
 
26
- rb_scan_args(argc, argv, "2*", &doc, &content, &rest);
26
+ rb_scan_args(argc, argv, "2*", &rb_document, &rb_content, &rb_rest);
27
27
 
28
- if (rb_obj_is_kind_of(doc, cNokogiriXmlDocument)) {
29
- xml_doc = noko_xml_document_unwrap(doc);
30
- } else {
28
+ if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlNode)) {
29
+ rb_raise(rb_eTypeError,
30
+ "expected first parameter to be a Nokogiri::XML::Document, received %"PRIsVALUE,
31
+ rb_obj_class(rb_document));
32
+ }
33
+
34
+ if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
31
35
  xmlNodePtr deprecated_node_type_arg;
32
- // TODO: deprecate allowing Node
33
- NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to CDATA.new is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
34
- Noko_Node_Get_Struct(doc, xmlNode, deprecated_node_type_arg);
35
- xml_doc = deprecated_node_type_arg->doc;
36
+ NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to CDATA.new is deprecated. Please pass a Document instead. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.15.3, remove in v1.17.0
37
+ Noko_Node_Get_Struct(rb_document, xmlNode, deprecated_node_type_arg);
38
+ c_document = deprecated_node_type_arg->doc;
39
+ } else {
40
+ c_document = noko_xml_document_unwrap(rb_document);
36
41
  }
37
42
 
38
- if (!NIL_P(content)) {
39
- content_str = (xmlChar *)StringValuePtr(content);
40
- content_str_len = RSTRING_LENINT(content);
43
+ if (!NIL_P(rb_content)) {
44
+ c_content = (xmlChar *)StringValuePtr(rb_content);
45
+ c_content_len = RSTRING_LENINT(rb_content);
41
46
  }
42
47
 
43
- node = xmlNewCDataBlock(xml_doc, content_str, content_str_len);
48
+ c_node = xmlNewCDataBlock(c_document, c_content, c_content_len);
44
49
 
45
- noko_xml_document_pin_node(node);
50
+ noko_xml_document_pin_node(c_node);
46
51
 
47
- rb_node = noko_xml_node_wrap(klass, node);
52
+ rb_node = noko_xml_node_wrap(klass, c_node);
48
53
  rb_obj_call_init(rb_node, argc, argv);
49
54
 
50
55
  if (rb_block_given_p()) { rb_yield(rb_node); }
@@ -61,5 +66,5 @@ noko_init_xml_cdata(void)
61
66
  */
62
67
  cNokogiriXmlCData = rb_define_class_under(mNokogiriXml, "CDATA", cNokogiriXmlText);
63
68
 
64
- rb_define_singleton_method(cNokogiriXmlCData, "new", new, -1);
69
+ rb_define_singleton_method(cNokogiriXmlCData, "new", rb_xml_cdata_s_new, -1);
65
70
  }
@@ -74,8 +74,10 @@ dealloc(void *data)
74
74
 
75
75
  ruby_xfree(doc->_private);
76
76
 
77
+ #if defined(__GNUC__) && __GNUC__ >= 5
77
78
  #pragma GCC diagnostic push
78
79
  #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // xmlDeregisterNodeDefault is deprecated as of libxml2 2.11.0
80
+ #endif
79
81
  /*
80
82
  * libxml-ruby < 3.0.0 uses xmlDeregisterNodeDefault. If the user is using one of those older
81
83
  * versions, the registered callback from libxml-ruby will access the _private pointers set by
@@ -90,7 +92,9 @@ dealloc(void *data)
90
92
  if (xmlDeregisterNodeDefaultValue) {
91
93
  remove_private((xmlNodePtr)doc);
92
94
  }
95
+ #if defined(__GNUC__) && __GNUC__ >= 5
93
96
  #pragma GCC diagnostic pop
97
+ #endif
94
98
 
95
99
  xmlFreeDoc(doc);
96
100
  }
@@ -100,11 +104,15 @@ memsize_node(const xmlNodePtr node)
100
104
  {
101
105
  /* note we don't count namespace definitions, just going for a good-enough number here */
102
106
  xmlNodePtr child;
107
+ xmlAttrPtr property;
103
108
  size_t memsize = 0;
104
109
 
105
110
  memsize += xmlStrlen(node->name);
106
- for (child = (xmlNodePtr)node->properties; child; child = child->next) {
107
- memsize += sizeof(xmlAttr) + memsize_node(child);
111
+
112
+ if (node->type == XML_ELEMENT_NODE) {
113
+ for (property = node->properties; property; property = property->next) {
114
+ memsize += sizeof(xmlAttr) + memsize_node((xmlNodePtr)property);
115
+ }
108
116
  }
109
117
  if (node->type == XML_TEXT_NODE) {
110
118
  memsize += xmlStrlen(node->content);
@@ -333,7 +341,7 @@ read_io(VALUE klass,
333
341
  xmlSetStructuredErrorFunc(NULL, NULL);
334
342
 
335
343
  if (doc == NULL) {
336
- xmlErrorPtr error;
344
+ xmlErrorConstPtr error;
337
345
 
338
346
  xmlFreeDoc(doc);
339
347
 
@@ -379,7 +387,7 @@ read_memory(VALUE klass,
379
387
  xmlSetStructuredErrorFunc(NULL, NULL);
380
388
 
381
389
  if (doc == NULL) {
382
- xmlErrorPtr error;
390
+ xmlErrorConstPtr error;
383
391
 
384
392
  xmlFreeDoc(doc);
385
393
 
@@ -533,7 +541,7 @@ create_entity(int argc, VALUE *argv, VALUE self)
533
541
  );
534
542
 
535
543
  if (NULL == ptr) {
536
- xmlErrorPtr error = xmlGetLastError();
544
+ xmlErrorConstPtr error = xmlGetLastError();
537
545
  if (error) {
538
546
  rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
539
547
  } else {
@@ -42,7 +42,6 @@ _xml_namespace_dealloc(void *ptr)
42
42
  xmlFree(ns);
43
43
  }
44
44
 
45
- #ifdef HAVE_RB_GC_LOCATION
46
45
  static void
47
46
  _xml_namespace_update_references(void *ptr)
48
47
  {
@@ -51,9 +50,6 @@ _xml_namespace_update_references(void *ptr)
51
50
  ns->_private = (void *)rb_gc_location((VALUE)ns->_private);
52
51
  }
53
52
  }
54
- #else
55
- # define _xml_namespace_update_references 0
56
- #endif
57
53
 
58
54
  static const rb_data_type_t nokogiri_xml_namespace_type_with_dealloc = {
59
55
  .wrap_struct_name = "Nokogiri::XML::Namespace#with_dealloc",
@@ -28,7 +28,6 @@ _xml_node_mark(void *ptr)
28
28
  }
29
29
  }
30
30
 
31
- #ifdef HAVE_RB_GC_LOCATION
32
31
  static void
33
32
  _xml_node_update_references(void *ptr)
34
33
  {
@@ -38,9 +37,6 @@ _xml_node_update_references(void *ptr)
38
37
  node->_private = (void *)rb_gc_location((VALUE)node->_private);
39
38
  }
40
39
  }
41
- #else
42
- # define _xml_node_update_references 0
43
- #endif
44
40
 
45
41
  static const rb_data_type_t nokogiri_node_type = {
46
42
  .wrap_struct_name = "Nokogiri::XML::Node",
@@ -350,7 +346,7 @@ ok:
350
346
 
351
347
  xmlUnlinkNode(original_reparentee);
352
348
 
353
- if (prf != xmlAddPrevSibling && prf != xmlAddNextSibling
349
+ if (prf != xmlAddPrevSibling && prf != xmlAddNextSibling && prf != xmlAddChild
354
350
  && reparentee->type == XML_TEXT_NODE && pivot->next && pivot->next->type == XML_TEXT_NODE) {
355
351
  /*
356
352
  * libxml merges text nodes in a right-to-left fashion, meaning that if
@@ -961,7 +957,7 @@ internal_subset(VALUE self)
961
957
  * - +new_parent_doc+
962
958
  * The new node's parent Document. Defaults to the this node's document.
963
959
  *
964
- * [Returns] The new Nokgiri::XML::Node
960
+ * [Returns] The new Nokogiri::XML::Node
965
961
  */
966
962
  static VALUE
967
963
  duplicate_node(int argc, VALUE *argv, VALUE self)
@@ -2058,8 +2054,7 @@ rb_xml_node_new(int argc, VALUE *argv, VALUE klass)
2058
2054
  rb_raise(rb_eArgError, "document must be a Nokogiri::XML::Node");
2059
2055
  }
2060
2056
  if (!rb_obj_is_kind_of(rb_document_node, cNokogiriXmlDocument)) {
2061
- // TODO: deprecate allowing Node
2062
- NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in a future release of Nokogiri.");
2057
+ NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.13.0, remove in v1.17.0
2063
2058
  }
2064
2059
  Noko_Node_Get_Struct(rb_document_node, xmlNode, c_document_node);
2065
2060
 
@@ -2138,7 +2133,7 @@ process_xincludes(VALUE self, VALUE options)
2138
2133
  xmlSetStructuredErrorFunc(NULL, NULL);
2139
2134
 
2140
2135
  if (rcode < 0) {
2141
- xmlErrorPtr error;
2136
+ xmlErrorConstPtr error;
2142
2137
 
2143
2138
  error = xmlGetLastError();
2144
2139
  if (error) {
@@ -2174,6 +2169,8 @@ in_context(VALUE self, VALUE _str, VALUE _options)
2174
2169
 
2175
2170
  /* Twiddle global variable because of a bug in libxml2.
2176
2171
  * http://git.gnome.org/browse/libxml2/commit/?id=e20fb5a72c83cbfc8e4a8aa3943c6be8febadab7
2172
+ *
2173
+ * TODO: this is fixed, and HTML_PARSE_NOIMPLIED is defined, in libxml2 2.7.7
2177
2174
  */
2178
2175
  #ifndef HTML_PARSE_NOIMPLIED
2179
2176
  htmlHandleOmittedElem(0);
@@ -5,8 +5,14 @@ VALUE cNokogiriXmlReader;
5
5
  static void
6
6
  xml_reader_deallocate(void *data)
7
7
  {
8
+ // free the document separately because we _may_ have triggered preservation by calling
9
+ // xmlTextReaderCurrentDoc during a read_more.
8
10
  xmlTextReaderPtr reader = data;
11
+ xmlDocPtr doc = xmlTextReaderCurrentDoc(reader);
9
12
  xmlFreeTextReader(reader);
13
+ if (doc) {
14
+ xmlFreeDoc(doc);
15
+ }
10
16
  }
11
17
 
12
18
  static const rb_data_type_t xml_reader_type = {
@@ -166,48 +172,6 @@ rb_xml_reader_namespaces(VALUE rb_reader)
166
172
  return rb_namespaces ;
167
173
  }
168
174
 
169
- /*
170
- :call-seq: attribute_nodes() → Array<Nokogiri::XML::Attr>
171
-
172
- Get the attributes of the current node as an Array of XML:Attr
173
-
174
- ⚠ This method is deprecated and unsafe to use. It will be removed in a future version of Nokogiri.
175
-
176
- See related: #attribute_hash, #attributes
177
- */
178
- static VALUE
179
- rb_xml_reader_attribute_nodes(VALUE rb_reader)
180
- {
181
- xmlTextReaderPtr c_reader;
182
- xmlNodePtr c_node;
183
- VALUE attr_nodes;
184
- int j;
185
-
186
- // TODO: deprecated, remove in Nokogiri v1.15, see https://github.com/sparklemotion/nokogiri/issues/2598
187
- // After removal, we can also remove all the "node_has_a_document" special handling from xml_node.c
188
- NOKO_WARN_DEPRECATION("Reader#attribute_nodes is deprecated and will be removed in a future version of Nokogiri. Please use Reader#attribute_hash instead.");
189
-
190
- TypedData_Get_Struct(rb_reader, xmlTextReader, &xml_reader_type, c_reader);
191
-
192
- if (! has_attributes(c_reader)) {
193
- return rb_ary_new() ;
194
- }
195
-
196
- c_node = xmlTextReaderExpand(c_reader);
197
- if (c_node == NULL) {
198
- return Qnil;
199
- }
200
-
201
- attr_nodes = noko_xml_node_attrs(c_node);
202
-
203
- /* ensure that the Reader won't be GCed as long as a node is referenced */
204
- for (j = 0 ; j < RARRAY_LEN(attr_nodes) ; j++) {
205
- rb_iv_set(rb_ary_entry(attr_nodes, j), "@reader", rb_reader);
206
- }
207
-
208
- return attr_nodes;
209
- }
210
-
211
175
  /*
212
176
  :call-seq: attribute_hash() → Hash<String ⇒ String>
213
177
 
@@ -554,9 +518,10 @@ static VALUE
554
518
  read_more(VALUE self)
555
519
  {
556
520
  xmlTextReaderPtr reader;
557
- xmlErrorPtr error;
521
+ xmlErrorConstPtr error;
558
522
  VALUE error_list;
559
523
  int ret;
524
+ xmlDocPtr c_document;
560
525
 
561
526
  TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
562
527
 
@@ -566,6 +531,16 @@ read_more(VALUE self)
566
531
  ret = xmlTextReaderRead(reader);
567
532
  xmlSetStructuredErrorFunc(NULL, NULL);
568
533
 
534
+ c_document = xmlTextReaderCurrentDoc(reader);
535
+ if (c_document && c_document->encoding == NULL) {
536
+ VALUE constructor_encoding = rb_iv_get(self, "@encoding");
537
+ if (RTEST(constructor_encoding)) {
538
+ c_document->encoding = xmlStrdup(BAD_CAST StringValueCStr(constructor_encoding));
539
+ } else {
540
+ c_document->encoding = xmlStrdup(BAD_CAST "UTF-8");
541
+ }
542
+ }
543
+
569
544
  if (ret == 1) { return self; }
570
545
  if (ret == 0) { return Qnil; }
571
546
 
@@ -749,15 +724,18 @@ rb_xml_reader_encoding(VALUE rb_reader)
749
724
  const char *parser_encoding;
750
725
  VALUE constructor_encoding;
751
726
 
727
+ TypedData_Get_Struct(rb_reader, xmlTextReader, &xml_reader_type, c_reader);
728
+ parser_encoding = (const char *)xmlTextReaderConstEncoding(c_reader);
729
+ if (parser_encoding) {
730
+ return NOKOGIRI_STR_NEW2(parser_encoding);
731
+ }
732
+
752
733
  constructor_encoding = rb_iv_get(rb_reader, "@encoding");
753
734
  if (RTEST(constructor_encoding)) {
754
735
  return constructor_encoding;
755
736
  }
756
737
 
757
- TypedData_Get_Struct(rb_reader, xmlTextReader, &xml_reader_type, c_reader);
758
- parser_encoding = (const char *)xmlTextReaderConstEncoding(c_reader);
759
- if (parser_encoding == NULL) { return Qnil; }
760
- return NOKOGIRI_STR_NEW2(parser_encoding);
738
+ return Qnil;
761
739
  }
762
740
 
763
741
  void
@@ -778,7 +756,6 @@ noko_init_xml_reader(void)
778
756
  rb_define_method(cNokogiriXmlReader, "attribute", reader_attribute, 1);
779
757
  rb_define_method(cNokogiriXmlReader, "attribute_at", attribute_at, 1);
780
758
  rb_define_method(cNokogiriXmlReader, "attribute_count", attribute_count, 0);
781
- rb_define_method(cNokogiriXmlReader, "attribute_nodes", rb_xml_reader_attribute_nodes, 0);
782
759
  rb_define_method(cNokogiriXmlReader, "attribute_hash", rb_xml_reader_attribute_hash, 0);
783
760
  rb_define_method(cNokogiriXmlReader, "attributes?", attributes_eh, 0);
784
761
  rb_define_method(cNokogiriXmlReader, "base_uri", rb_xml_reader_base_uri, 0);
@@ -93,7 +93,7 @@ xml_relax_ng_parse_schema(
93
93
  xmlRelaxNGFreeParserCtxt(c_parser_context);
94
94
 
95
95
  if (NULL == c_schema) {
96
- xmlErrorPtr error = xmlGetLastError();
96
+ xmlErrorConstPtr error = xmlGetLastError();
97
97
  if (error) {
98
98
  Nokogiri_error_raise(NULL, error);
99
99
  } else {
@@ -59,6 +59,10 @@ parse_io(VALUE klass, VALUE io, VALUE encoding)
59
59
  (xmlInputReadCallback)noko_io_read,
60
60
  (xmlInputCloseCallback)noko_io_close,
61
61
  (void *)io, enc);
62
+ if (!ctxt) {
63
+ rb_raise(rb_eRuntimeError, "failed to create xml sax parser context");
64
+ }
65
+
62
66
  if (ctxt->sax) {
63
67
  xmlFree(ctxt->sax);
64
68
  ctxt->sax = NULL;
@@ -59,7 +59,7 @@ native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
59
59
 
60
60
  if (xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
61
61
  if (!(ctx->options & XML_PARSE_RECOVER)) {
62
- xmlErrorPtr e = xmlCtxtGetLastError(ctx);
62
+ xmlErrorConstPtr e = xmlCtxtGetLastError(ctx);
63
63
  Nokogiri_error_raise(NULL, e);
64
64
  }
65
65
  }
@@ -146,7 +146,7 @@ xml_schema_parse_schema(
146
146
  xmlSchemaFreeParserCtxt(c_parser_context);
147
147
 
148
148
  if (NULL == c_schema) {
149
- xmlErrorPtr error = xmlGetLastError();
149
+ xmlErrorConstPtr error = xmlGetLastError();
150
150
  if (error) {
151
151
  Nokogiri_error_raise(NULL, error);
152
152
  } else {
@@ -203,7 +203,7 @@ read_memory(int argc, VALUE *argv, VALUE klass)
203
203
  * [Returns] Nokogiri::XML::Schema
204
204
  */
205
205
  static VALUE
206
- from_document(int argc, VALUE *argv, VALUE klass)
206
+ rb_xml_schema_s_from_document(int argc, VALUE *argv, VALUE klass)
207
207
  {
208
208
  VALUE rb_document;
209
209
  VALUE rb_parse_options;
@@ -214,14 +214,19 @@ from_document(int argc, VALUE *argv, VALUE klass)
214
214
 
215
215
  rb_scan_args(argc, argv, "11", &rb_document, &rb_parse_options);
216
216
 
217
- if (rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
218
- c_document = noko_xml_document_unwrap(rb_document);
219
- } else {
217
+ if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlNode)) {
218
+ rb_raise(rb_eTypeError,
219
+ "expected parameter to be a Nokogiri::XML::Document, received %"PRIsVALUE,
220
+ rb_obj_class(rb_document));
221
+ }
222
+
223
+ if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
220
224
  xmlNodePtr deprecated_node_type_arg;
221
- // TODO: deprecate allowing Node
222
- NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
225
+ NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.15.3, remove in v1.17.0
223
226
  Noko_Node_Get_Struct(rb_document, xmlNode, deprecated_node_type_arg);
224
227
  c_document = deprecated_node_type_arg->doc;
228
+ } else {
229
+ c_document = noko_xml_document_unwrap(rb_document);
225
230
  }
226
231
 
227
232
  if (noko_xml_document_has_wrapped_blank_nodes_p(c_document)) {
@@ -249,7 +254,7 @@ noko_init_xml_schema(void)
249
254
  rb_undef_alloc_func(cNokogiriXmlSchema);
250
255
 
251
256
  rb_define_singleton_method(cNokogiriXmlSchema, "read_memory", read_memory, -1);
252
- rb_define_singleton_method(cNokogiriXmlSchema, "from_document", from_document, -1);
257
+ rb_define_singleton_method(cNokogiriXmlSchema, "from_document", rb_xml_schema_s_from_document, -1);
253
258
 
254
259
  rb_define_private_method(cNokogiriXmlSchema, "validate_document", validate_document, 1);
255
260
  rb_define_private_method(cNokogiriXmlSchema, "validate_file", validate_file, 1);
@@ -26,7 +26,7 @@ Nokogiri_structured_error_func_restore(libxmlStructuredErrorHandlerState *handle
26
26
  }
27
27
 
28
28
  void
29
- Nokogiri_error_array_pusher(void *ctx, xmlErrorPtr error)
29
+ Nokogiri_error_array_pusher(void *ctx, xmlErrorConstPtr error)
30
30
  {
31
31
  VALUE list = (VALUE)ctx;
32
32
  Check_Type(list, T_ARRAY);
@@ -34,13 +34,13 @@ Nokogiri_error_array_pusher(void *ctx, xmlErrorPtr error)
34
34
  }
35
35
 
36
36
  void
37
- Nokogiri_error_raise(void *ctx, xmlErrorPtr error)
37
+ Nokogiri_error_raise(void *ctx, xmlErrorConstPtr error)
38
38
  {
39
39
  rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
40
40
  }
41
41
 
42
42
  VALUE
43
- Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error)
43
+ Nokogiri_wrap_xml_syntax_error(xmlErrorConstPtr error)
44
44
  {
45
45
  VALUE msg, e, klass;
46
46