nokogiri 1.19.3-aarch64-linux-gnu → 1.19.4-aarch64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef67c67345d63d916b9f8785718c985d0900a409864833df3d3a7e76ca9a7943
4
- data.tar.gz: 6c055b94cee733a2d0c5b6879b54765864431254a8d66ffd862fc56f6370384c
3
+ metadata.gz: 30fb7b9d08d9f1e514757972ac4d818cad0d3780f83c96072f342d7a5db1bd72
4
+ data.tar.gz: ef4146245dd8ac186b05d693a7c23051482b172b600dba5c8eb2f0866f301ee1
5
5
  SHA512:
6
- metadata.gz: 17f5baed7e4e7e3e4805d7a315d525e460826fbc9f2791fd3d2410c9efed45b30f98da5252f671ea61c066b8d811272ac31fe29457ec975493c6e6885c028eb4
7
- data.tar.gz: 2fe92e99719ad08363137065b3a4a635ccf6a4ba1149c208e9f52800bb7e35c76a7c29191e74e3711cbffacf9751921055b56821443b6dc0d52c4afe3a7471e2
6
+ metadata.gz: a71cb46a28f4f374fd130092bb3433ed53457edcc6754386eb8417c9184a6716e9943a2c870b3cd15ec3634c84a9dbbe156a5ce017150b4c85f09d2433a3532e
7
+ data.tar.gz: a5ac58eafd0c719cf341a53f31697737078e49f13d2e455e388830cbb2398f645a22fb69295751abff6ac3b2002479239d6231e04b9e4909d9a20ff52b8286ae
@@ -203,9 +203,6 @@ Init_nokogiri(void)
203
203
  rb_const_set(mNokogiri, rb_intern("LIBXSLT_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION));
204
204
  rb_const_set(mNokogiri, rb_intern("LIBXSLT_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xsltEngineVersion));
205
205
 
206
- rb_const_set(mNokogiri, rb_intern("LIBXML_ZLIB_ENABLED"),
207
- xmlHasFeature(XML_WITH_ZLIB) == 1 ? Qtrue : Qfalse);
208
-
209
206
  #ifdef NOKOGIRI_PACKAGED_LIBRARIES
210
207
  rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
211
208
  # ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
@@ -228,6 +225,12 @@ Init_nokogiri(void)
228
225
  rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse);
229
226
  #endif
230
227
 
228
+ rb_const_set(mNokogiri, rb_intern("LIBXML_ZLIB_ENABLED"),
229
+ xmlHasFeature(XML_WITH_ZLIB) == 1 ? Qtrue : Qfalse);
230
+
231
+ rb_const_set(mNokogiri, rb_intern("LIBXML_HTTP_ENABLED"),
232
+ xmlHasFeature(XML_WITH_HTTP) == 1 ? Qtrue : Qfalse);
233
+
231
234
  #ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS
232
235
  rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
233
236
  #endif
@@ -181,8 +181,17 @@ int noko_io_read(void *ctx, char *buffer, int len);
181
181
  int noko_io_write(void *ctx, char *buffer, int len);
182
182
  int noko_io_close(void *ctx);
183
183
 
184
- #define Noko_Node_Get_Struct(obj,type,sval) ((sval) = (type*)DATA_PTR(obj))
185
- #define Noko_Namespace_Get_Struct(obj,type,sval) ((sval) = (type*)DATA_PTR(obj))
184
+ static inline void *
185
+ _noko_data_ptr(VALUE rb_object)
186
+ {
187
+ void *c_data = DATA_PTR(rb_object);
188
+ if (c_data == NULL) {
189
+ rb_raise(rb_eRuntimeError, "Uninitialized %" PRIsVALUE " struct (null data pointer)", rb_obj_class(rb_object));
190
+ }
191
+ return c_data;
192
+ }
193
+ #define Noko_Node_Get_Struct(obj,type,sval) ((sval) = (type*)_noko_data_ptr(obj))
194
+ #define Noko_Namespace_Get_Struct(obj,type,sval) ((sval) = (type*)_noko_data_ptr(obj))
186
195
 
187
196
  VALUE noko_xml_node_wrap(VALUE klass, xmlNodePtr node) ;
188
197
  VALUE noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set) ;
@@ -10,37 +10,42 @@ VALUE cNokogiriXmlAttr;
10
10
  * (e.g., a HTML boolean attribute).
11
11
  */
12
12
  static VALUE
13
- set_value(VALUE self, VALUE content)
13
+ noko_xml_attr_set_value(VALUE self, VALUE content)
14
14
  {
15
15
  xmlAttrPtr attr;
16
- xmlChar *value;
17
- xmlNode *cur;
18
16
 
19
17
  Noko_Node_Get_Struct(self, xmlAttr, attr);
20
18
 
21
- if (attr->children) {
22
- xmlFreeNodeList(attr->children);
19
+ {
20
+ /* Unlink and pin any wrapped children */
21
+ xmlNode *cur = attr->children;
22
+ xmlNode *next;
23
+
24
+ while (cur) {
25
+ next = cur->next;
26
+ if (cur->_private) {
27
+ xmlUnlinkNode(cur);
28
+ noko_xml_document_pin_node(cur);
29
+ }
30
+ cur = next;
31
+ }
23
32
  }
24
- attr->children = attr->last = NULL;
25
33
 
26
34
  if (content == Qnil) {
27
- return content;
28
- }
29
-
30
- value = xmlEncodeEntitiesReentrant(attr->doc, (unsigned char *)StringValueCStr(content));
31
- if (xmlStrlen(value) == 0) {
32
- attr->children = xmlNewDocText(attr->doc, value);
35
+ xmlNodeSetContent((xmlNodePtr)attr, NULL); /* Clear any remaining unwrapped children. */
33
36
  } else {
34
- attr->children = xmlStringGetNodeList(attr->doc, value);
35
- }
36
- xmlFree(value);
37
+ xmlChar *value = xmlEncodeEntitiesReentrant(attr->doc, (unsigned char *)StringValueCStr(content));
38
+
39
+ if (xmlStrlen(value) == 0) {
40
+ xmlNodeSetContent((xmlNodePtr)attr, NULL); /* Clear any remaining unwrapped children. */
37
41
 
38
- for (cur = attr->children; cur; cur = cur->next) {
39
- cur->parent = (xmlNode *)attr;
40
- cur->doc = attr->doc;
41
- if (cur->next == NULL) {
42
- attr->last = cur;
42
+ /* Preserve empty-string attributes as `foo=""` and not boolean `foo` */
43
+ attr->children = attr->last = xmlNewDocText(attr->doc, value);
44
+ attr->children->parent = (xmlNode *)attr;
45
+ } else {
46
+ xmlNodeSetContent((xmlNodePtr)attr, value);
43
47
  }
48
+ xmlFree(value);
44
49
  }
45
50
 
46
51
  return content;
@@ -53,7 +58,7 @@ set_value(VALUE self, VALUE content)
53
58
  * Create a new Attr element on the +document+ with +name+
54
59
  */
55
60
  static VALUE
56
- new (int argc, VALUE *argv, VALUE klass)
61
+ noko_xml_attr__new(int argc, VALUE *argv, VALUE klass)
57
62
  {
58
63
  xmlDocPtr xml_doc;
59
64
  VALUE document;
@@ -97,7 +102,7 @@ noko_init_xml_attr(void)
97
102
  */
98
103
  cNokogiriXmlAttr = rb_define_class_under(mNokogiriXml, "Attr", cNokogiriXmlNode);
99
104
 
100
- rb_define_singleton_method(cNokogiriXmlAttr, "new", new, -1);
105
+ rb_define_singleton_method(cNokogiriXmlAttr, "new", noko_xml_attr__new, -1);
101
106
 
102
- rb_define_method(cNokogiriXmlAttr, "value=", set_value, 1);
107
+ rb_define_method(cNokogiriXmlAttr, "value=", noko_xml_attr_set_value, 1);
103
108
  }
@@ -255,12 +255,6 @@ rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
255
255
 
256
256
  c_document = noko_xml_document_unwrap(self);
257
257
 
258
- c_current_root = xmlDocGetRootElement(c_document);
259
- if (c_current_root) {
260
- xmlUnlinkNode(c_current_root);
261
- noko_xml_document_pin_node(c_current_root);
262
- }
263
-
264
258
  if (!NIL_P(rb_new_root)) {
265
259
  if (!rb_obj_is_kind_of(rb_new_root, cNokogiriXmlNode)) {
266
260
  rb_raise(rb_eArgError,
@@ -270,13 +264,23 @@ rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
270
264
 
271
265
  Noko_Node_Get_Struct(rb_new_root, xmlNode, c_new_root);
272
266
 
273
- /* If the new root's document is not the same as the current document,
274
- * then we need to dup the node in to this document. */
275
- if (c_new_root->doc != c_document) {
276
- c_new_root = xmlDocCopyNode(c_new_root, c_document, 1);
277
- if (!c_new_root) {
278
- rb_raise(rb_eRuntimeError, "Could not reparent node (xmlDocCopyNode)");
279
- }
267
+ if (c_new_root->type != XML_ELEMENT_NODE) {
268
+ rb_raise(rb_eTypeError, "root must be a Nokogiri::XML::Element");
269
+ }
270
+ }
271
+
272
+ c_current_root = xmlDocGetRootElement(c_document);
273
+ if (c_current_root) {
274
+ xmlUnlinkNode(c_current_root);
275
+ noko_xml_document_pin_node(c_current_root);
276
+ }
277
+
278
+ /* If the new root's document is not the same as the current document,
279
+ * then we need to dup the node in to this document. */
280
+ if (c_new_root && c_new_root->doc != c_document) {
281
+ c_new_root = xmlDocCopyNode(c_new_root, c_document, 1);
282
+ if (!c_new_root) {
283
+ rb_raise(rb_eRuntimeError, "Could not reparent node (xmlDocCopyNode)");
280
284
  }
281
285
  }
282
286
 
@@ -317,12 +321,13 @@ static VALUE
317
321
  set_encoding(VALUE self, VALUE encoding)
318
322
  {
319
323
  xmlDocPtr doc = noko_xml_document_unwrap(self);
324
+ xmlChar *new_encoding = xmlStrdup((xmlChar *)StringValueCStr(encoding));
320
325
 
321
326
  if (doc->encoding) {
322
327
  xmlFree(DISCARD_CONST_QUAL_XMLCHAR(doc->encoding));
323
328
  }
324
329
 
325
- doc->encoding = xmlStrdup((xmlChar *)StringValueCStr(encoding));
330
+ doc->encoding = new_encoding;
326
331
 
327
332
  return encoding;
328
333
  }
@@ -708,6 +713,9 @@ noko_xml_document_unwrap(VALUE rb_document)
708
713
  {
709
714
  xmlDocPtr c_document;
710
715
  TypedData_Get_Struct(rb_document, xmlDoc, &xml_doc_type, c_document);
716
+ if (c_document == NULL) {
717
+ rb_raise(rb_eRuntimeError, "Uninitialized %" PRIsVALUE " struct (null data pointer)", rb_obj_class(rb_document));
718
+ }
711
719
  return c_document;
712
720
  }
713
721
 
@@ -971,6 +971,10 @@ rb_xml_node_initialize_copy_with_args(VALUE rb_self, VALUE rb_other, VALUE rb_le
971
971
  xmlDocPtr c_new_parent_doc;
972
972
  VALUE rb_node_cache;
973
973
 
974
+ if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNode)) {
975
+ rb_raise(rb_eTypeError, "argument must be a kind of Nokogiri::XML::Node");
976
+ }
977
+
974
978
  Noko_Node_Get_Struct(rb_other, xmlNode, c_other);
975
979
  c_level = (int)NUM2INT(rb_level);
976
980
  c_new_parent_doc = noko_xml_document_unwrap(rb_new_parent_doc);
@@ -2150,25 +2154,20 @@ compare(VALUE self, VALUE _other)
2150
2154
 
2151
2155
 
2152
2156
  /*
2153
- * call-seq:
2154
- * process_xincludes(flags)
2155
- *
2156
- * Loads and substitutes all xinclude elements below the node. The
2157
- * parser context will be initialized with +flags+.
2157
+ * Run XInclude substitution over the tree rooted at +c_node+, with the parser context initialized
2158
+ * from +c_flags+. Collects libxml2's structured errors and raises Nokogiri::XML::SyntaxError (or
2159
+ * RuntimeError) on failure.
2158
2160
  */
2159
- static VALUE
2160
- noko_xml_node__process_xincludes(VALUE rb_node, VALUE rb_flags)
2161
+ static void
2162
+ _noko_xml_node_process_xinclude_subtree(xmlNodePtr c_node, int c_flags)
2161
2163
  {
2162
2164
  int status ;
2163
- xmlNodePtr c_node;
2164
2165
  VALUE rb_errors = rb_ary_new();
2165
2166
  libxmlStructuredErrorHandlerState handler_state;
2166
2167
 
2167
- Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
2168
-
2169
2168
  noko__structured_error_func_save_and_set(&handler_state, (void *)rb_errors, noko__error_array_pusher);
2170
2169
 
2171
- status = xmlXIncludeProcessTreeFlags(c_node, (int)NUM2INT(rb_flags));
2170
+ status = xmlXIncludeProcessTreeFlags(c_node, c_flags);
2172
2171
 
2173
2172
  noko__structured_error_func_restore(&handler_state);
2174
2173
 
@@ -2181,11 +2180,77 @@ noko_xml_node__process_xincludes(VALUE rb_node, VALUE rb_flags)
2181
2180
  rb_raise(rb_eRuntimeError, "Could not perform xinclude substitution");
2182
2181
  }
2183
2182
  }
2183
+ }
2184
+
2185
+
2186
+ /*
2187
+ * Whether +c_node+ is an <xi:include> element in either the 2001 or 2003 XInclude namespace.
2188
+ */
2189
+ static int
2190
+ _noko_xml_node_xinclude_element_p(xmlNodePtr c_node)
2191
+ {
2192
+ return c_node->type == XML_ELEMENT_NODE
2193
+ && xmlStrEqual(c_node->name, XINCLUDE_NODE)
2194
+ && c_node->ns != NULL
2195
+ && (xmlStrEqual(c_node->ns->href, XINCLUDE_NS) || xmlStrEqual(c_node->ns->href, XINCLUDE_OLD_NS));
2196
+ }
2197
+
2198
+
2199
+ /*
2200
+ * call-seq:
2201
+ * process_xincludes(flags)
2202
+ *
2203
+ * Loads and substitutes all xinclude elements below the node. The
2204
+ * parser context will be initialized with +flags+.
2205
+ */
2206
+ static VALUE
2207
+ noko_xml_node__process_xincludes(VALUE rb_node, VALUE rb_flags)
2208
+ {
2209
+ xmlNodePtr c_node;
2210
+
2211
+ Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
2212
+
2213
+ if (c_node->parent == NULL && _noko_xml_node_xinclude_element_p(c_node)) {
2214
+ rb_raise(rb_eRuntimeError, "cannot process XInclude on an unlinked <xi:include> node");
2215
+ }
2216
+
2217
+ _noko_xml_node_process_xinclude_subtree(c_node, (int)NUM2INT(rb_flags));
2184
2218
 
2185
2219
  return rb_node;
2186
2220
  }
2187
2221
 
2188
2222
 
2223
+ /*
2224
+ * Process this single <xi:include> node, substituting an unwrapped copy of it in its place so
2225
+ * that libxml2 frees the copy. This node is unlinked and pinned to the document, so any Ruby
2226
+ * wrapper for it (or for its descendants or namespaces) keeps pointing at valid memory. The
2227
+ * parser context is initialized with +flags+.
2228
+ */
2229
+ static VALUE
2230
+ noko_xml_node__safe_process_xinclude(VALUE rb_node, VALUE rb_flags)
2231
+ {
2232
+ xmlNodePtr c_node, c_copy;
2233
+
2234
+ Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
2235
+
2236
+ if (c_node->parent == NULL) {
2237
+ rb_raise(rb_eRuntimeError, "cannot process XInclude on an unlinked <xi:include> node");
2238
+ }
2239
+
2240
+ c_copy = xmlDocCopyNode(c_node, c_node->doc, 1);
2241
+ if (c_copy == NULL) {
2242
+ rb_raise(rb_eRuntimeError, "Could not copy node for xinclude substitution");
2243
+ }
2244
+
2245
+ xmlReplaceNode(c_node, c_copy);
2246
+ noko_xml_document_pin_node(c_node);
2247
+
2248
+ _noko_xml_node_process_xinclude_subtree(c_copy, (int)NUM2INT(rb_flags));
2249
+
2250
+ return Qnil;
2251
+ }
2252
+
2253
+
2189
2254
  /* TODO: DOCUMENT ME */
2190
2255
  static VALUE
2191
2256
  in_context(VALUE self, VALUE _str, VALUE _options)
@@ -2286,9 +2351,7 @@ in_context(VALUE self, VALUE _str, VALUE _options)
2286
2351
  VALUE
2287
2352
  rb_xml_node_data_ptr_eh(VALUE self)
2288
2353
  {
2289
- xmlNodePtr c_node;
2290
- Noko_Node_Get_Struct(self, xmlNode, c_node);
2291
- return c_node ? Qtrue : Qfalse;
2354
+ return DATA_PTR(self) ? Qtrue : Qfalse;
2292
2355
  }
2293
2356
 
2294
2357
  VALUE
@@ -2438,6 +2501,7 @@ noko_init_xml_node(void)
2438
2501
  rb_define_method(cNokogiriXmlNode, "unlink", unlink_node, 0);
2439
2502
 
2440
2503
  rb_define_protected_method(cNokogiriXmlNode, "initialize_copy_with_args", rb_xml_node_initialize_copy_with_args, 3);
2504
+ rb_define_protected_method(cNokogiriXmlNode, "safe_process_xinclude", noko_xml_node__safe_process_xinclude, 1);
2441
2505
 
2442
2506
  rb_define_private_method(cNokogiriXmlNode, "add_child_node", add_child, 1);
2443
2507
  rb_define_private_method(cNokogiriXmlNode, "add_next_sibling_node", add_next_sibling, 1);
@@ -304,7 +304,7 @@ index_at(VALUE rb_self, long offset)
304
304
 
305
305
  TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
306
306
 
307
- if (offset >= c_self->nodeNr || abs((int)offset) > c_self->nodeNr) {
307
+ if (offset >= c_self->nodeNr || offset < -c_self->nodeNr) {
308
308
  return Qnil;
309
309
  }
310
310
 
@@ -11,6 +11,15 @@ static const xmlChar *NOKOGIRI_URI = (const xmlChar *)"http://www.nokogiri.org/d
11
11
  static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-builtin";
12
12
  static const xmlChar *NOKOGIRI_BUILTIN_URI = (const xmlChar *)"https://www.nokogiri.org/default_ns/ruby/builtins";
13
13
 
14
+ static void
15
+ _noko_xml_xpath_context_dmark(void *data)
16
+ {
17
+ xmlXPathContextPtr c_context = data;
18
+ if (c_context->doc && DOC_RUBY_OBJECT_TEST(c_context->doc)) {
19
+ rb_gc_mark(DOC_RUBY_OBJECT(c_context->doc));
20
+ }
21
+ }
22
+
14
23
  static void
15
24
  _noko_xml_xpath_context_dfree(void *data)
16
25
  {
@@ -21,9 +30,10 @@ _noko_xml_xpath_context_dfree(void *data)
21
30
  static const rb_data_type_t _noko_xml_xpath_context_type = {
22
31
  .wrap_struct_name = "xmlXPathContext",
23
32
  .function = {
33
+ .dmark = _noko_xml_xpath_context_dmark,
24
34
  .dfree = _noko_xml_xpath_context_dfree,
25
35
  },
26
- .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
36
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
27
37
  };
28
38
 
29
39
  /* find a CSS class in an HTML element's `class` attribute */
Binary file
Binary file
Binary file
Binary file
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Nokogiri
4
4
  # The version of Nokogiri you are using
5
- VERSION = "1.19.3"
5
+ VERSION = "1.19.4"
6
6
  end
@@ -53,6 +53,14 @@ module Nokogiri
53
53
  defined?(Nokogiri::LIBXML_ICONV_ENABLED) && Nokogiri::LIBXML_ICONV_ENABLED
54
54
  end
55
55
 
56
+ def libxml2_has_zlib?
57
+ defined?(Nokogiri::LIBXML_ZLIB_ENABLED) && Nokogiri::LIBXML_ZLIB_ENABLED
58
+ end
59
+
60
+ def libxml2_has_http?
61
+ defined?(Nokogiri::LIBXML_HTTP_ENABLED) && Nokogiri::LIBXML_HTTP_ENABLED
62
+ end
63
+
56
64
  def libxslt_has_datetime?
57
65
  defined?(Nokogiri::LIBXSLT_DATETIME_ENABLED) && Nokogiri::LIBXSLT_DATETIME_ENABLED
58
66
  end
@@ -145,6 +153,8 @@ module Nokogiri
145
153
  end
146
154
  libxml["memory_management"] = Nokogiri::LIBXML_MEMORY_MANAGEMENT
147
155
  libxml["iconv_enabled"] = libxml2_has_iconv?
156
+ libxml["zlib_enabled"] = libxml2_has_zlib?
157
+ libxml["http_enabled"] = libxml2_has_http?
148
158
  libxml["compiled"] = compiled_libxml_version.to_s
149
159
  libxml["loaded"] = loaded_libxml_version.to_s
150
160
  end
@@ -85,8 +85,9 @@ module Nokogiri
85
85
  read_memory(string_or_io, url, encoding, options.to_i)
86
86
  end
87
87
 
88
- # do xinclude processing
89
- doc.do_xinclude(options) if options.xinclude?
88
+ # do xinclude processing; the document is freshly parsed and unexposed to Ruby, so the
89
+ # defensive copy is unnecessary
90
+ doc.do_xinclude(options, safe_copy: false) if options.xinclude?
90
91
 
91
92
  doc
92
93
  end
@@ -523,16 +523,67 @@ module Nokogiri
523
523
  set_namespace(ns)
524
524
  end
525
525
 
526
+ XINCLUDE_NAMESPACES = {
527
+ "xi2001" => "http://www.w3.org/2001/XInclude",
528
+ "xi2003" => "http://www.w3.org/2003/XInclude",
529
+ }.freeze
530
+ private_constant :XINCLUDE_NAMESPACES
531
+
532
+ # Every top-level <xi:include> in the subtree, in either XInclude namespace, excluding
533
+ # includes nested inside another include's fallback (libxml2 only expands those if the
534
+ # parent include fails).
535
+ XINCLUDE_QUERY =
536
+ "descendant-or-self::xi2001:include[not(ancestor::xi2001:include) and not(ancestor::xi2003:include)] | " \
537
+ "descendant-or-self::xi2003:include[not(ancestor::xi2001:include) and not(ancestor::xi2003:include)]"
538
+ private_constant :XINCLUDE_QUERY
539
+
526
540
  ###
527
- # Do xinclude substitution on the subtree below node. If given a block, a
528
- # Nokogiri::XML::ParseOptions object initialized from +options+, will be
529
- # passed to it, allowing more convenient modification of the parser options.
530
- def do_xinclude(options = XML::ParseOptions::DEFAULT_XML)
541
+ # :call-seq:
542
+ # do_xinclude(options = ParseOptions::DEFAULT_XML, safe_copy: true) self
543
+ # do_xinclude(options = ParseOptions::DEFAULT_XML, safe_copy: true) { |options| ... } self
544
+ #
545
+ # Do XInclude substitution on the subtree below this node, replacing each +<xi:include>+ with
546
+ # the content it references.
547
+ #
548
+ # [Parameters]
549
+ # - +options+ (Nokogiri::XML::ParseOptions) The parser options for the substitution. (default
550
+ # +ParseOptions::DEFAULT_XML+)
551
+ #
552
+ # [Optional Keyword Arguments]
553
+ # - +safe_copy:+ (Boolean) Operate on a defensive copy of each +<xi:include>+ element, to
554
+ # prevent libxml2 from freeing memory that is bound to live Ruby objects. (default +true+)
555
+ #
556
+ # When +true+, each +<xi:include>+ is processed on an unwrapped copy of itself, so libxml2
557
+ # frees the copy while the original node is unlinked from the document and kept alive. This
558
+ # prevents a use-after-free when the +<xi:include>+ node, or any of its descendants or
559
+ # namespaces, has already been exposed to Ruby; as a consequence such a wrapped node ends up
560
+ # detached from the document rather than removed or converted in place.
561
+ #
562
+ # When +false+, the document is processed in place. This is faster but only safe when nothing
563
+ # in the subtree has been exposed to Ruby (for example, immediately after parsing), which is
564
+ # why Document.parse uses it.
565
+ #
566
+ # This option has no effect on the pure-Java backend, which performs XInclude substitution
567
+ # during parsing.
568
+ #
569
+ # [Yields]
570
+ # If a block is given, a Nokogiri::XML::ParseOptions object initialized from +options+ is
571
+ # yielded to it, which can be configured before substitution.
572
+ #
573
+ # [Returns] +self+ (Nokogiri::XML::Node)
574
+ def do_xinclude(options = XML::ParseOptions::DEFAULT_XML, safe_copy: true)
531
575
  options = Nokogiri::XML::ParseOptions.new(options) if Integer === options
532
576
  yield options if block_given?
533
577
 
534
- # call c extension
535
- process_xincludes(options.to_i)
578
+ if safe_copy && Nokogiri.uses_libxml?
579
+ xpath(XINCLUDE_QUERY, XINCLUDE_NAMESPACES).each do |include_node|
580
+ include_node.safe_process_xinclude(options.to_i)
581
+ end
582
+ else
583
+ process_xincludes(options.to_i)
584
+ end
585
+
586
+ self
536
587
  end
537
588
 
538
589
  alias_method :next, :next_sibling
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.3
4
+ version: 1.19.4
5
5
  platform: aarch64-linux-gnu
6
6
  authors:
7
7
  - Mike Dalessio