nokogiri 1.19.1 → 1.19.4

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: 1ae5314c9ce62610588d318eec8c0bf0a97dc25e6af588c9004e7e3c421077d0
4
- data.tar.gz: 597f493954d25c1a142865337942d736e727864cc5f928ff670e1c9bbb137f5b
3
+ metadata.gz: b195d6ddd64bd4812056a21283c42ac51a161c99a0763d2cbb0a174e1d03fd12
4
+ data.tar.gz: 375787a6a2a62d3d3d394e5bef11e2d1dbb3a1d238af31ffee7e46575d6fe877
5
5
  SHA512:
6
- metadata.gz: abdc2d58bafbc4af7509fce3876350ee380957e0b923d0b417232f96e821e11327e4b39a588f999ce30a2b4ea945d84ea6b0379f577983ac5ea20ebd012edf39
7
- data.tar.gz: fc5962e33192032e76ccdb94b7c37c534cc0231b1a5ec78b4aea69bf153cb4ae8c6dfc379465dd79b7a7b6b5f0025077cf82db118d35d3cfcb769b85bd8d0727
6
+ metadata.gz: 58a9b6de3ff04d37308d889127f0be4e5c08c6780a20084324684be26e9e8544d81b6a4406d3c78d6980dd645c12c9093583d7c7aacb133a9a96ecda6cabe2c0
7
+ data.tar.gz: 7f3f742d0510193f0a612ecade4e0115264c6229f09e53a8c750aa7032a5a7d810924ddf5d7c4cd048be14b0c0800e52032ad937536c1f5e8efff4caa0357d15
@@ -25,6 +25,7 @@ Note that this document is broken into multiple sections, each of which describe
25
25
  * [net.sourceforge.htmlunit:neko-htmlunit](#netsourceforgehtmlunitneko-htmlunit)
26
26
  * [nu.validator:jing](#nuvalidatorjing)
27
27
  * [org.nokogiri:nekodtd](#orgnokogirinekodtd)
28
+ * [org.xmlresolver:xmlresolver](#orgxmlresolverxmlresolver)
28
29
  * [xalan:serializer and xalan:xalan](#xalanserializer-and-xalanxalan)
29
30
  * [xerces:xercesImpl](#xercesxercesimpl)
30
31
  * [xml-apis:xml-apis](#xml-apisxml-apis)
@@ -98,6 +99,7 @@ The Java platform release distributes the following dependencies as compiled jar
98
99
  * [net.sourceforge.htmlunit:neko-htmlunit](#netsourceforgehtmlunitneko-htmlunit)
99
100
  * [nu.validator:jing](#nuvalidatorjing)
100
101
  * [org.nokogiri:nekodtd](#orgnokogirinekodtd)
102
+ * [org.xmlresolver:xmlresolver](#orgxmlresolverxmlresolver)
101
103
  * [xalan:serializer and xalan:xalan](#xalanserializer-and-xalanxalan)
102
104
  * [xerces:xercesImpl](#xercesxercesimpl)
103
105
  * [xml-apis:xml-apis](#xml-apisxml-apis)
@@ -1661,6 +1663,191 @@ https://github.com/sparklemotion/nekodtd
1661
1663
  END OF TERMS AND CONDITIONS
1662
1664
 
1663
1665
 
1666
+ ### org.xmlresolver:xmlresolver
1667
+
1668
+ Apache 2.0
1669
+
1670
+ https://xmlresolver.org/
1671
+
1672
+ Apache License
1673
+ Version 2.0, January 2004
1674
+ http://www.apache.org/licenses/
1675
+
1676
+
1677
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1678
+
1679
+ 1. Definitions.
1680
+
1681
+ "License" shall mean the terms and conditions for use, reproduction,
1682
+ and distribution as defined by Sections 1 through 9 of this document.
1683
+
1684
+ "Licensor" shall mean the copyright owner or entity authorized by
1685
+ the copyright owner that is granting the License.
1686
+
1687
+ "Legal Entity" shall mean the union of the acting entity and all
1688
+ other entities that control, are controlled by, or are under common
1689
+ control with that entity. For the purposes of this definition,
1690
+ "control" means (i) the power, direct or indirect, to cause the
1691
+ direction or management of such entity, whether by contract or
1692
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
1693
+ outstanding shares, or (iii) beneficial ownership of such entity.
1694
+
1695
+ "You" (or "Your") shall mean an individual or Legal Entity
1696
+ exercising permissions granted by this License.
1697
+
1698
+ "Source" form shall mean the preferred form for making modifications,
1699
+ including but not limited to software source code, documentation
1700
+ source, and configuration files.
1701
+
1702
+ "Object" form shall mean any form resulting from mechanical
1703
+ transformation or translation of a Source form, including but
1704
+ not limited to compiled object code, generated documentation,
1705
+ and conversions to other media types.
1706
+
1707
+ "Work" shall mean the work of authorship, whether in Source or
1708
+ Object form, made available under the License, as indicated by a
1709
+ copyright notice that is included in or attached to the work
1710
+ (an example is provided in the Appendix below).
1711
+
1712
+ "Derivative Works" shall mean any work, whether in Source or Object
1713
+ form, that is based on (or derived from) the Work and for which the
1714
+ editorial revisions, annotations, elaborations, or other modifications
1715
+ represent, as a whole, an original work of authorship. For the purposes
1716
+ of this License, Derivative Works shall not include works that remain
1717
+ separable from, or merely link (or bind by name) to the interfaces of,
1718
+ the Work and Derivative Works thereof.
1719
+
1720
+ "Contribution" shall mean any work of authorship, including
1721
+ the original version of the Work and any modifications or additions
1722
+ to that Work or Derivative Works thereof, that is intentionally
1723
+ submitted to Licensor for inclusion in the Work by the copyright owner
1724
+ or by an individual or Legal Entity authorized to submit on behalf of
1725
+ the copyright owner. For the purposes of this definition, "submitted"
1726
+ means any form of electronic, verbal, or written communication sent
1727
+ to the Licensor or its representatives, including but not limited to
1728
+ communication on electronic mailing lists, source code control systems,
1729
+ and issue tracking systems that are managed by, or on behalf of, the
1730
+ Licensor for the purpose of discussing and improving the Work, but
1731
+ excluding communication that is conspicuously marked or otherwise
1732
+ designated in writing by the copyright owner as "Not a Contribution."
1733
+
1734
+ "Contributor" shall mean Licensor and any individual or Legal Entity
1735
+ on behalf of whom a Contribution has been received by Licensor and
1736
+ subsequently incorporated within the Work.
1737
+
1738
+ 2. Grant of Copyright License. Subject to the terms and conditions of
1739
+ this License, each Contributor hereby grants to You a perpetual,
1740
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
1741
+ copyright license to reproduce, prepare Derivative Works of,
1742
+ publicly display, publicly perform, sublicense, and distribute the
1743
+ Work and such Derivative Works in Source or Object form.
1744
+
1745
+ 3. Grant of Patent License. Subject to the terms and conditions of
1746
+ this License, each Contributor hereby grants to You a perpetual,
1747
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
1748
+ (except as stated in this section) patent license to make, have made,
1749
+ use, offer to sell, sell, import, and otherwise transfer the Work,
1750
+ where such license applies only to those patent claims licensable
1751
+ by such Contributor that are necessarily infringed by their
1752
+ Contribution(s) alone or by combination of their Contribution(s)
1753
+ with the Work to which such Contribution(s) was submitted. If You
1754
+ institute patent litigation against any entity (including a
1755
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
1756
+ or a Contribution incorporated within the Work constitutes direct
1757
+ or contributory patent infringement, then any patent licenses
1758
+ granted to You under this License for that Work shall terminate
1759
+ as of the date such litigation is filed.
1760
+
1761
+ 4. Redistribution. You may reproduce and distribute copies of the
1762
+ Work or Derivative Works thereof in any medium, with or without
1763
+ modifications, and in Source or Object form, provided that You
1764
+ meet the following conditions:
1765
+
1766
+ (a) You must give any other recipients of the Work or
1767
+ Derivative Works a copy of this License; and
1768
+
1769
+ (b) You must cause any modified files to carry prominent notices
1770
+ stating that You changed the files; and
1771
+
1772
+ (c) You must retain, in the Source form of any Derivative Works
1773
+ that You distribute, all copyright, patent, trademark, and
1774
+ attribution notices from the Source form of the Work,
1775
+ excluding those notices that do not pertain to any part of
1776
+ the Derivative Works; and
1777
+
1778
+ (d) If the Work includes a "NOTICE" text file as part of its
1779
+ distribution, then any Derivative Works that You distribute must
1780
+ include a readable copy of the attribution notices contained
1781
+ within such NOTICE file, excluding those notices that do not
1782
+ pertain to any part of the Derivative Works, in at least one
1783
+ of the following places: within a NOTICE text file distributed
1784
+ as part of the Derivative Works; within the Source form or
1785
+ documentation, if provided along with the Derivative Works; or,
1786
+ within a display generated by the Derivative Works, if and
1787
+ wherever such third-party notices normally appear. The contents
1788
+ of the NOTICE file are for informational purposes only and
1789
+ do not modify the License. You may add Your own attribution
1790
+ notices within Derivative Works that You distribute, alongside
1791
+ or as an addendum to the NOTICE text from the Work, provided
1792
+ that such additional attribution notices cannot be construed
1793
+ as modifying the License.
1794
+
1795
+ You may add Your own copyright statement to Your modifications and
1796
+ may provide additional or different license terms and conditions
1797
+ for use, reproduction, or distribution of Your modifications, or
1798
+ for any such Derivative Works as a whole, provided Your use,
1799
+ reproduction, and distribution of the Work otherwise complies with
1800
+ the conditions stated in this License.
1801
+
1802
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
1803
+ any Contribution intentionally submitted for inclusion in the Work
1804
+ by You to the Licensor shall be under the terms and conditions of
1805
+ this License, without any additional terms or conditions.
1806
+ Notwithstanding the above, nothing herein shall supersede or modify
1807
+ the terms of any separate license agreement you may have executed
1808
+ with Licensor regarding such Contributions.
1809
+
1810
+ 6. Trademarks. This License does not grant permission to use the trade
1811
+ names, trademarks, service marks, or product names of the Licensor,
1812
+ except as required for reasonable and customary use in describing the
1813
+ origin of the Work and reproducing the content of the NOTICE file.
1814
+
1815
+ 7. Disclaimer of Warranty. Unless required by applicable law or
1816
+ agreed to in writing, Licensor provides the Work (and each
1817
+ Contributor provides its Contributions) on an "AS IS" BASIS,
1818
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1819
+ implied, including, without limitation, any warranties or conditions
1820
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
1821
+ PARTICULAR PURPOSE. You are solely responsible for determining the
1822
+ appropriateness of using or redistributing the Work and assume any
1823
+ risks associated with Your exercise of permissions under this License.
1824
+
1825
+ 8. Limitation of Liability. In no event and under no legal theory,
1826
+ whether in tort (including negligence), contract, or otherwise,
1827
+ unless required by applicable law (such as deliberate and grossly
1828
+ negligent acts) or agreed to in writing, shall any Contributor be
1829
+ liable to You for damages, including any direct, indirect, special,
1830
+ incidental, or consequential damages of any character arising as a
1831
+ result of this License or out of the use or inability to use the
1832
+ Work (including but not limited to damages for loss of goodwill,
1833
+ work stoppage, computer failure or malfunction, or any and all
1834
+ other commercial damages or losses), even if such Contributor
1835
+ has been advised of the possibility of such damages.
1836
+
1837
+ 9. Accepting Warranty or Additional Liability. While redistributing
1838
+ the Work or Derivative Works thereof, You may choose to offer,
1839
+ and charge a fee for, acceptance of support, warranty, indemnity,
1840
+ or other liability obligations and/or rights consistent with this
1841
+ License. However, in accepting such obligations, You may act only
1842
+ on Your own behalf and on Your sole responsibility, not on behalf
1843
+ of any other Contributor, and only if You agree to indemnify,
1844
+ defend, and hold each Contributor harmless for any liability
1845
+ incurred by, or claims asserted against, such Contributor by reason
1846
+ of your accepting any such warranty or additional liability.
1847
+
1848
+ END OF TERMS AND CONDITIONS
1849
+
1850
+
1664
1851
  ### xalan:serializer and xalan:xalan
1665
1852
 
1666
1853
  Apache 2.0
@@ -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 */
@@ -133,6 +133,35 @@ rb_xslt_stylesheet_serialize(VALUE self, VALUE xmlobj)
133
133
  return rval ;
134
134
  }
135
135
 
136
+
137
+ /*
138
+ * Build the C-string params array passed to xsltApplyStylesheet.
139
+ *
140
+ * Note: params[j] is a raw pointer into a Ruby string's buffer, and we do not pin the underlying
141
+ * VALUEs against GC compaction. This is safe (despite not pinning the VALUEs) because libxslt fully
142
+ * processes params (interning names, evaluating values) before template execution begins, and Ruby
143
+ * callbacks can only run during template execution. By the time GC compaction is reachable, libxslt
144
+ * no longer reads params[].
145
+ */
146
+ typedef struct {
147
+ VALUE rb_param;
148
+ long param_len;
149
+ const char **params;
150
+ } build_xslt_params_args_t;
151
+
152
+ static VALUE
153
+ build_xslt_params(VALUE args_ptr)
154
+ {
155
+ build_xslt_params_args_t *args = (build_xslt_params_args_t *)args_ptr;
156
+
157
+ for (long j = 0; j < args->param_len; j++) {
158
+ VALUE entry = rb_ary_entry(args->rb_param, j);
159
+ args->params[j] = StringValueCStr(entry);
160
+ }
161
+
162
+ return Qnil;
163
+ }
164
+
136
165
  /*
137
166
  * call-seq:
138
167
  * transform(document)
@@ -254,7 +283,7 @@ rb_xslt_stylesheet_transform(int argc, VALUE *argv, VALUE self)
254
283
  xmlDocPtr c_result_document ;
255
284
  nokogiriXsltStylesheetTuple *wrapper;
256
285
  const char **params ;
257
- long param_len, j ;
286
+ long param_len ;
258
287
  int parse_error_occurred ;
259
288
  int defensive_copy_p = 0;
260
289
 
@@ -277,10 +306,17 @@ rb_xslt_stylesheet_transform(int argc, VALUE *argv, VALUE self)
277
306
 
278
307
  param_len = RARRAY_LEN(rb_param);
279
308
  params = ruby_xcalloc((size_t)param_len + 1, sizeof(char *));
280
- for (j = 0 ; j < param_len ; j++) {
281
- VALUE entry = rb_ary_entry(rb_param, j);
282
- const char *ptr = StringValueCStr(entry);
283
- params[j] = ptr;
309
+ {
310
+ // populate params under rb_protect so that a raise from StringValueCStr
311
+ // (e.g. on a null byte) does not leak the params allocation.
312
+ build_xslt_params_args_t args = { rb_param, param_len, params };
313
+ int state = 0;
314
+
315
+ rb_protect(build_xslt_params, (VALUE)&args, &state);
316
+ if (state) {
317
+ ruby_xfree(params);
318
+ rb_jump_tag(state);
319
+ }
284
320
  }
285
321
  params[param_len] = 0 ;
286
322
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #--
3
3
  # DO NOT MODIFY!!!!
4
- # This file is automatically generated by rex 1.0.7
4
+ # This file is automatically generated by rex 1.0.8
5
5
  # from lexical definition file "lib/nokogiri/css/tokenizer.rex".
6
6
  #++
7
7
 
@@ -63,13 +63,13 @@ class Tokenizer
63
63
  when (text = @ss.scan(/has\([\s]*/))
64
64
  action { [:HAS, text] }
65
65
 
66
- when (text = @ss.scan(/-?([_A-Za-z]|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))([_A-Za-z0-9-]|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))*\([\s]*/))
66
+ when (text = @ss.scan(/-?(?>[_A-Za-z]|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))(?>[_A-Za-z0-9-]|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))*\([\s]*/))
67
67
  action { [:FUNCTION, text] }
68
68
 
69
- when (text = @ss.scan(/-?([_A-Za-z]|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))([_A-Za-z0-9-]|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))*/))
69
+ when (text = @ss.scan(/-?(?>[_A-Za-z]|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))(?>[_A-Za-z0-9-]|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))*/))
70
70
  action { [:IDENT, text] }
71
71
 
72
- when (text = @ss.scan(/\#([_A-Za-z0-9-]|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))+/))
72
+ when (text = @ss.scan(/\#(?>[_A-Za-z0-9-]|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))+/))
73
73
  action { [:HASH, text] }
74
74
 
75
75
  when (text = @ss.scan(/[\s]*~=[\s]*/))
@@ -132,7 +132,7 @@ class Tokenizer
132
132
  when (text = @ss.scan(/[\s]+/))
133
133
  action { [:S, text] }
134
134
 
135
- when (text = @ss.scan(/("([^\n\r\f"]|(\n|\r\n|\r|\f)|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))*(?<!\\)(?:\\{2})*"|'([^\n\r\f']|(\n|\r\n|\r|\f)|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))*(?<!\\)(?:\\{2})*')/))
135
+ when (text = @ss.scan(/("(?>[^\n\r\f"\\]|\\?(\n|\r\n|\r|\f)|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))*"|'(?>[^\n\r\f'\\]|\\?(\n|\r\n|\r|\f)|[^\0-\177]|(\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f]))*')/))
136
136
  action { [:STRING, text] }
137
137
 
138
138
  when (text = @ss.scan(/./))
@@ -11,13 +11,13 @@ macro
11
11
  unicode \\[0-9A-Fa-f]{1,6}(\r\n|[\s])?
12
12
 
13
13
  escape ({unicode}|\\[^\n\r\f0-9A-Fa-f])
14
- nmchar ([_A-Za-z0-9-]|{nonascii}|{escape})
15
- nmstart ([_A-Za-z]|{nonascii}|{escape})
14
+ nmchar (?>[_A-Za-z0-9-]|{nonascii}|{escape})
15
+ nmstart (?>[_A-Za-z]|{nonascii}|{escape})
16
16
  name {nmstart}{nmchar}*
17
17
  ident -?{name}
18
18
  charref {nmchar}+
19
- string1 "([^\n\r\f"]|{nl}|{nonascii}|{escape})*(?<!\\)(?:\\{2})*"
20
- string2 '([^\n\r\f']|{nl}|{nonascii}|{escape})*(?<!\\)(?:\\{2})*'
19
+ string1 "(?>[^\n\r\f"\\]|\\?{nl}|{nonascii}|{escape})*"
20
+ string2 '(?>[^\n\r\f'\\]|\\?{nl}|{nonascii}|{escape})*'
21
21
  string ({string1}|{string2})
22
22
 
23
23
  rule
@@ -2,37 +2,42 @@
2
2
  begin
3
3
  require 'jar_dependencies'
4
4
  rescue LoadError
5
- require 'xalan/serializer/2.7.3/serializer-2.7.3.jar'
5
+ require 'isorelax/isorelax/20030108/isorelax-20030108.jar'
6
+ require 'org/nokogiri/nekodtd/0.1.11.noko2/nekodtd-0.1.11.noko2.jar'
6
7
  require 'net/sourceforge/htmlunit/neko-htmlunit/2.63.0/neko-htmlunit-2.63.0.jar'
8
+ require 'net/sf/saxon/Saxon-HE/12.7/Saxon-HE-12.7.jar'
9
+ require 'org/xmlresolver/xmlresolver/5.3.3/xmlresolver-5.3.3.jar'
10
+ require 'org/xmlresolver/xmlresolver/5.3.3/xmlresolver-5.3.3-data.jar'
7
11
  require 'nu/validator/jing/20200702VNU/jing-20200702VNU.jar'
8
- require 'xerces/xercesImpl/2.12.2/xercesImpl-2.12.2.jar'
9
- require 'net/sf/saxon/Saxon-HE/9.6.0-4/Saxon-HE-9.6.0-4.jar'
12
+ require 'xalan/serializer/2.7.3/serializer-2.7.3.jar'
10
13
  require 'xalan/xalan/2.7.3/xalan-2.7.3.jar'
14
+ require 'xerces/xercesImpl/2.12.2/xercesImpl-2.12.2.jar'
11
15
  require 'xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar'
12
- require 'org/nokogiri/nekodtd/0.1.11.noko2/nekodtd-0.1.11.noko2.jar'
13
- require 'isorelax/isorelax/20030108/isorelax-20030108.jar'
14
16
  end
15
17
 
16
18
  if defined? Jars
17
- require_jar 'xalan', 'serializer', '2.7.3'
19
+ require_jar 'isorelax', 'isorelax', '20030108'
20
+ require_jar 'org.nokogiri', 'nekodtd', '0.1.11.noko2'
18
21
  require_jar 'net.sourceforge.htmlunit', 'neko-htmlunit', '2.63.0'
22
+ require_jar 'net.sf.saxon', 'Saxon-HE', '12.7'
23
+ require_jar 'org.xmlresolver', 'xmlresolver', '5.3.3'
24
+ require_jar 'org.xmlresolver', 'xmlresolver', 'data', '5.3.3'
19
25
  require_jar 'nu.validator', 'jing', '20200702VNU'
20
- require_jar 'xerces', 'xercesImpl', '2.12.2'
21
- require_jar 'net.sf.saxon', 'Saxon-HE', '9.6.0-4'
26
+ require_jar 'xalan', 'serializer', '2.7.3'
22
27
  require_jar 'xalan', 'xalan', '2.7.3'
28
+ require_jar 'xerces', 'xercesImpl', '2.12.2'
23
29
  require_jar 'xml-apis', 'xml-apis', '1.4.01'
24
- require_jar 'org.nokogiri', 'nekodtd', '0.1.11.noko2'
25
- require_jar 'isorelax', 'isorelax', '20030108'
26
30
  end
27
31
 
28
32
  module Nokogiri
29
33
  # generated by the :vendor_jars rake task
30
34
  JAR_DEPENDENCIES = {
31
35
  "isorelax:isorelax" => "20030108",
32
- "net.sf.saxon:Saxon-HE" => "9.6.0-4",
36
+ "net.sf.saxon:Saxon-HE" => "12.7",
33
37
  "net.sourceforge.htmlunit:neko-htmlunit" => "2.63.0",
34
38
  "nu.validator:jing" => "20200702VNU",
35
39
  "org.nokogiri:nekodtd" => "0.1.11.noko2",
40
+ "org.xmlresolver:xmlresolver" => "5.3.3",
36
41
  "xalan:serializer" => "2.7.3",
37
42
  "xalan:xalan" => "2.7.3",
38
43
  "xerces:xercesImpl" => "2.12.2",
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Nokogiri
4
4
  # The version of Nokogiri you are using
5
- VERSION = "1.19.1"
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
@@ -76,12 +76,12 @@ module Nokogiri
76
76
  #
77
77
  # ⚠ This option enables entity substitution, contrary to what the name implies.
78
78
  #
79
- # <b>It is UNSAFE to set this option</b> when parsing untrusted documents.
79
+ # 🛡 <b>It is UNSAFE to set this option</b> when parsing untrusted documents.
80
80
  NOENT = 1 << 1
81
81
 
82
82
  # Load external subsets. On by default for XSLT::Stylesheet.
83
83
  #
84
- # <b>It is UNSAFE to set this option</b> when parsing untrusted documents.
84
+ # 🛡 <b>It is UNSAFE to set this option</b> when parsing untrusted documents.
85
85
  DTDLOAD = 1 << 2
86
86
 
87
87
  # Default DTD attributes. On by default for XSLT::Stylesheet.
@@ -111,7 +111,7 @@ module Nokogiri
111
111
  # Forbid network access. On by default for XML::Document, XML::DocumentFragment,
112
112
  # HTML4::Document, HTML4::DocumentFragment, XSLT::Stylesheet, and XML::Schema.
113
113
  #
114
- # <b>It is UNSAFE to unset this option</b> when parsing untrusted documents.
114
+ # 🛡 <b>It is UNSAFE to unset this option</b> when parsing untrusted documents.
115
115
  NONET = 1 << 11
116
116
 
117
117
  # Do not reuse the context dictionary. Off by default.
@@ -128,8 +128,7 @@ module Nokogiri
128
128
 
129
129
  # Compact small text nodes. Off by default.
130
130
  #
131
- # ⚠ No modification of the DOM tree is allowed after parsing. libxml2 may crash if you try to
132
- # modify the tree.
131
+ # ⚠ No modification of the DOM tree is allowed after parsing.
133
132
  COMPACT = 1 << 16
134
133
 
135
134
  # Parse using XML-1.0 before update 5. Off by default
@@ -140,7 +139,7 @@ module Nokogiri
140
139
 
141
140
  # Relax any hardcoded limit from the parser. Off by default.
142
141
  #
143
- # <b>It is UNSAFE to set this option</b> when parsing untrusted documents.
142
+ # 🛡 <b>It is UNSAFE to set this option</b> when parsing untrusted documents.
144
143
  HUGE = 1 << 19
145
144
 
146
145
  # Support line numbers up to <code>long int</code> (default is a <code>short int</code>). On
@@ -151,7 +150,12 @@ module Nokogiri
151
150
  # The options mask used by default for parsing XML::Document and XML::DocumentFragment
152
151
  DEFAULT_XML = RECOVER | NONET | BIG_LINES
153
152
 
154
- # The options mask used by default used for parsing XSLT::Stylesheet
153
+ # Shorthand options mask useful for parsing XSLT stylesheets:
154
+ # sets RECOVER, NONET, NOENT, DTDLOAD, DTDATTR, NOCDATA, BIG_LINES.
155
+ #
156
+ # 🛡 This option set includes `NOENT` and `DTDLOAD` which are unsafe for untrusted
157
+ # documents. <b>Do not parse untrusted XSLT stylesheets.</b> See Nokogiri::XSLT for more
158
+ # information.
155
159
  DEFAULT_XSLT = RECOVER | NONET | NOENT | DTDLOAD | DTDATTR | NOCDATA | BIG_LINES
156
160
 
157
161
  # The options mask used by default used for parsing HTML4::Document and HTML4::DocumentFragment
@@ -39,7 +39,7 @@ module Nokogiri
39
39
  # of ParserContext#replace_entities. (Recall that the default value of
40
40
  # ParserContext#replace_entities is `false`.)
41
41
  #
42
- # <b>It is UNSAFE to set ParserContext#replace_entities to `true`</b> when parsing untrusted
42
+ # 🛡 <b>It is UNSAFE to set ParserContext#replace_entities to `true`</b> when parsing untrusted
43
43
  # documents.
44
44
  #
45
45
  # 💡 For more information on entity types, see [Wikipedia's page on
@@ -3,15 +3,20 @@
3
3
  module Nokogiri
4
4
  module XSLT
5
5
  ###
6
- # A Stylesheet represents an XSLT Stylesheet object. Stylesheet creation
7
- # is done through Nokogiri.XSLT. Here is an example of transforming
8
- # an XML::Document with a Stylesheet:
6
+ # A Stylesheet represents an XSLT Stylesheet object. Stylesheet creation is done through
7
+ # Nokogiri::XSLT.parse (or the convenience method Nokogiri.XSLT). Here is an example of
8
+ # transforming an XML::Document with a Stylesheet:
9
9
  #
10
10
  # doc = Nokogiri::XML(File.read('some_file.xml'))
11
11
  # xslt = Nokogiri::XSLT(File.read('some_transformer.xslt'))
12
12
  #
13
13
  # xslt.transform(doc) # => Nokogiri::XML::Document
14
14
  #
15
+ # 🛡 <b>This class does not support execution of untrusted stylesheets.</b> An untrusted
16
+ # stylesheet may consume a large amount of CPU, memory, or other system resources during
17
+ # transformation, and IO and file access are not restricted. See Nokogiri::XSLT for more
18
+ # information about the security implications of untrusted stylesheets.
19
+ #
15
20
  # Many XSLT transformations include serialization behavior to emit a non-XML document. For these
16
21
  # cases, please take care to invoke the #serialize method on the result of the transformation:
17
22
  #
data/lib/nokogiri/xslt.rb CHANGED
@@ -10,8 +10,14 @@ module Nokogiri
10
10
  end
11
11
 
12
12
  ###
13
- # See Nokogiri::XSLT::Stylesheet for creating and manipulating
14
- # Stylesheet object.
13
+ # See Nokogiri::XSLT::Stylesheet for creating and manipulating Stylesheet objects.
14
+ #
15
+ # 🛡 <b>Do not use this module for untrusted stylesheet documents.</b> libxslt does not support
16
+ # safely processing untrusted stylesheets. Untrusted stylesheets may access the file system and
17
+ # network, consume large amounts of CPU, memory, or other system resources, and IO and file
18
+ # access are not restricted. Additionally, the stylesheet is parsed by libxml2 with +NOENT+ and
19
+ # +DTDLOAD+ enabled (see ParseOptions::DEFAULT_XSLT), meaning that <b>external entities will be
20
+ # resolved and external subsets will be loaded</b> during parsing.
15
21
  module XSLT
16
22
  class << self
17
23
  # :call-seq:
@@ -20,6 +26,9 @@ module Nokogiri
20
26
  #
21
27
  # Parse the stylesheet in +xsl+, registering optional +modules+ as custom class handlers.
22
28
  #
29
+ # 🛡 <b>Do not pass untrusted stylesheet content to this method.</b> See Nokogiri::XSLT for more
30
+ # information.
31
+ #
23
32
  # [Parameters]
24
33
  # - +xsl+ (String) XSL content to be parsed into a stylesheet
25
34
  # - +modules+ (Hash<String ⇒ Class>) A hash of URI-to-handler relations for linking a
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.1
4
+ version: 1.19.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Dalessio
@@ -301,7 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
301
  - !ruby/object:Gem::Version
302
302
  version: '0'
303
303
  requirements: []
304
- rubygems_version: 4.0.3
304
+ rubygems_version: 4.0.6
305
305
  specification_version: 4
306
306
  summary: Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby.
307
307
  test_files: []