nokogiri 1.11.2 → 1.12.5

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 (127) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +243 -22
  3. data/LICENSE.md +1 -1
  4. data/README.md +7 -6
  5. data/dependencies.yml +12 -12
  6. data/ext/nokogiri/depend +35 -34
  7. data/ext/nokogiri/extconf.rb +185 -103
  8. data/ext/nokogiri/gumbo.c +584 -0
  9. data/ext/nokogiri/{html_document.c → html4_document.c} +8 -8
  10. data/ext/nokogiri/{html_element_description.c → html4_element_description.c} +21 -19
  11. data/ext/nokogiri/{html_entity_lookup.c → html4_entity_lookup.c} +7 -7
  12. data/ext/nokogiri/{html_sax_parser_context.c → html4_sax_parser_context.c} +6 -5
  13. data/ext/nokogiri/{html_sax_push_parser.c → html4_sax_push_parser.c} +4 -4
  14. data/ext/nokogiri/libxml2_backwards_compat.c +30 -30
  15. data/ext/nokogiri/nokogiri.c +70 -38
  16. data/ext/nokogiri/nokogiri.h +19 -9
  17. data/ext/nokogiri/xml_document.c +50 -49
  18. data/ext/nokogiri/xml_element_content.c +2 -0
  19. data/ext/nokogiri/xml_encoding_handler.c +11 -6
  20. data/ext/nokogiri/xml_namespace.c +4 -2
  21. data/ext/nokogiri/xml_node.c +147 -133
  22. data/ext/nokogiri/xml_node_set.c +20 -20
  23. data/ext/nokogiri/xml_reader.c +2 -0
  24. data/ext/nokogiri/xml_sax_parser.c +6 -6
  25. data/ext/nokogiri/xml_sax_parser_context.c +2 -0
  26. data/ext/nokogiri/xml_schema.c +2 -0
  27. data/ext/nokogiri/xml_xpath_context.c +67 -65
  28. data/ext/nokogiri/xslt_stylesheet.c +2 -1
  29. data/gumbo-parser/CHANGES.md +63 -0
  30. data/gumbo-parser/Makefile +101 -0
  31. data/gumbo-parser/THANKS +27 -0
  32. data/gumbo-parser/src/Makefile +34 -0
  33. data/gumbo-parser/src/README.md +41 -0
  34. data/gumbo-parser/src/ascii.c +75 -0
  35. data/gumbo-parser/src/ascii.h +115 -0
  36. data/gumbo-parser/src/attribute.c +42 -0
  37. data/gumbo-parser/src/attribute.h +17 -0
  38. data/gumbo-parser/src/char_ref.c +22225 -0
  39. data/gumbo-parser/src/char_ref.h +29 -0
  40. data/gumbo-parser/src/char_ref.rl +2154 -0
  41. data/gumbo-parser/src/error.c +626 -0
  42. data/gumbo-parser/src/error.h +148 -0
  43. data/gumbo-parser/src/foreign_attrs.c +104 -0
  44. data/gumbo-parser/src/foreign_attrs.gperf +27 -0
  45. data/gumbo-parser/src/gumbo.h +943 -0
  46. data/gumbo-parser/src/insertion_mode.h +33 -0
  47. data/gumbo-parser/src/macros.h +91 -0
  48. data/gumbo-parser/src/parser.c +4886 -0
  49. data/gumbo-parser/src/parser.h +41 -0
  50. data/gumbo-parser/src/replacement.h +33 -0
  51. data/gumbo-parser/src/string_buffer.c +103 -0
  52. data/gumbo-parser/src/string_buffer.h +68 -0
  53. data/gumbo-parser/src/string_piece.c +48 -0
  54. data/gumbo-parser/src/svg_attrs.c +174 -0
  55. data/gumbo-parser/src/svg_attrs.gperf +77 -0
  56. data/gumbo-parser/src/svg_tags.c +137 -0
  57. data/gumbo-parser/src/svg_tags.gperf +55 -0
  58. data/gumbo-parser/src/tag.c +222 -0
  59. data/gumbo-parser/src/tag_lookup.c +382 -0
  60. data/gumbo-parser/src/tag_lookup.gperf +169 -0
  61. data/gumbo-parser/src/tag_lookup.h +13 -0
  62. data/gumbo-parser/src/token_buffer.c +79 -0
  63. data/gumbo-parser/src/token_buffer.h +71 -0
  64. data/gumbo-parser/src/token_type.h +17 -0
  65. data/gumbo-parser/src/tokenizer.c +3463 -0
  66. data/gumbo-parser/src/tokenizer.h +112 -0
  67. data/gumbo-parser/src/tokenizer_states.h +339 -0
  68. data/gumbo-parser/src/utf8.c +245 -0
  69. data/gumbo-parser/src/utf8.h +164 -0
  70. data/gumbo-parser/src/util.c +68 -0
  71. data/gumbo-parser/src/util.h +30 -0
  72. data/gumbo-parser/src/vector.c +111 -0
  73. data/gumbo-parser/src/vector.h +45 -0
  74. data/lib/nokogiri/css/parser.rb +1 -1
  75. data/lib/nokogiri/css/parser.y +1 -1
  76. data/lib/nokogiri/css/syntax_error.rb +1 -1
  77. data/lib/nokogiri/css.rb +14 -14
  78. data/lib/nokogiri/extension.rb +7 -2
  79. data/lib/nokogiri/gumbo.rb +14 -0
  80. data/lib/nokogiri/html.rb +31 -27
  81. data/lib/nokogiri/{html → html4}/builder.rb +2 -2
  82. data/lib/nokogiri/{html → html4}/document.rb +4 -4
  83. data/lib/nokogiri/{html → html4}/document_fragment.rb +3 -3
  84. data/lib/nokogiri/{html → html4}/element_description.rb +1 -1
  85. data/lib/nokogiri/{html → html4}/element_description_defaults.rb +1 -1
  86. data/lib/nokogiri/{html → html4}/entity_lookup.rb +1 -1
  87. data/lib/nokogiri/{html → html4}/sax/parser.rb +11 -14
  88. data/lib/nokogiri/html4/sax/parser_context.rb +19 -0
  89. data/lib/nokogiri/{html → html4}/sax/push_parser.rb +5 -5
  90. data/lib/nokogiri/html4.rb +40 -0
  91. data/lib/nokogiri/html5/document.rb +74 -0
  92. data/lib/nokogiri/html5/document_fragment.rb +80 -0
  93. data/lib/nokogiri/html5/node.rb +93 -0
  94. data/lib/nokogiri/html5.rb +473 -0
  95. data/lib/nokogiri/version/constant.rb +1 -1
  96. data/lib/nokogiri/version/info.rb +12 -2
  97. data/lib/nokogiri/xml/builder.rb +38 -0
  98. data/lib/nokogiri/xml/document.rb +89 -17
  99. data/lib/nokogiri/xml/node/save_options.rb +1 -1
  100. data/lib/nokogiri/xml/node.rb +7 -5
  101. data/lib/nokogiri/xml/parse_options.rb +2 -0
  102. data/lib/nokogiri/xml/pp.rb +2 -2
  103. data/lib/nokogiri/xml/sax/document.rb +24 -30
  104. data/lib/nokogiri/xml/sax.rb +4 -4
  105. data/lib/nokogiri/xml/xpath.rb +2 -2
  106. data/lib/nokogiri/xml.rb +35 -36
  107. data/lib/nokogiri/xslt/stylesheet.rb +1 -1
  108. data/lib/nokogiri/xslt.rb +16 -16
  109. data/lib/nokogiri.rb +31 -29
  110. data/patches/libxml2/{0002-Remove-script-macro-support.patch → 0001-Remove-script-macro-support.patch} +0 -0
  111. data/patches/libxml2/{0003-Update-entities-to-remove-handling-of-ssi.patch → 0002-Update-entities-to-remove-handling-of-ssi.patch} +0 -0
  112. data/patches/libxml2/{0004-libxml2.la-is-in-top_builddir.patch → 0003-libxml2.la-is-in-top_builddir.patch} +1 -1
  113. data/patches/libxml2/{0008-use-glibc-strlen.patch → 0004-use-glibc-strlen.patch} +0 -0
  114. data/patches/libxml2/{0009-avoid-isnan-isinf.patch → 0005-avoid-isnan-isinf.patch} +4 -4
  115. data/patches/libxml2/0006-update-automake-files-for-arm64.patch +2511 -0
  116. data/patches/libxml2/0007-Fix-XPath-recursion-limit.patch +31 -0
  117. data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2511 -0
  118. data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +19 -0
  119. data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
  120. metadata +110 -69
  121. data/lib/nokogiri/html/sax/parser_context.rb +0 -17
  122. data/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch +0 -78
  123. data/patches/libxml2/0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch +0 -32
  124. data/patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch +0 -73
  125. data/patches/libxml2/0007-use-new-htmlParseLookupCommentEnd-to-find-comment-en.patch +0 -103
  126. data/patches/libxml2/0010-parser.c-shrink-the-input-buffer-when-appropriate.patch +0 -70
  127. data/ports/archives/libxml2-2.9.10.tar.gz +0 -0
@@ -2,7 +2,7 @@
2
2
 
3
3
  VALUE cNokogiriXmlNode ;
4
4
 
5
- static ID decorate, decorate_bang;
5
+ static ID id_decorate, id_decorate_bang;
6
6
 
7
7
  #ifdef DEBUG
8
8
  static void
@@ -36,6 +36,7 @@ static void
36
36
  relink_namespace(xmlNodePtr reparented)
37
37
  {
38
38
  xmlNodePtr child;
39
+ xmlAttrPtr attr;
39
40
 
40
41
  if (reparented->type != XML_ATTRIBUTE_NODE &&
41
42
  reparented->type != XML_ELEMENT_NODE) { return; }
@@ -69,7 +70,9 @@ relink_namespace(xmlNodePtr reparented)
69
70
  if (reparented->type != XML_ELEMENT_NODE || !reparented->parent) { return; }
70
71
 
71
72
  /* Make sure that our reparented node has the correct namespaces */
72
- if (!reparented->ns && reparented->doc != (xmlDocPtr)reparented->parent) {
73
+ if (!reparented->ns &&
74
+ (reparented->doc != (xmlDocPtr)reparented->parent) &&
75
+ (rb_iv_get(DOC_RUBY_OBJECT(reparented->doc), "@namespace_inheritance") == Qtrue)) {
73
76
  xmlSetNs(reparented, reparented->parent->ns);
74
77
  }
75
78
 
@@ -132,10 +135,10 @@ relink_namespace(xmlNodePtr reparented)
132
135
  }
133
136
 
134
137
  if (reparented->type == XML_ELEMENT_NODE) {
135
- child = (xmlNodePtr)((xmlElementPtr)reparented)->attributes;
136
- while (NULL != child) {
137
- relink_namespace(child);
138
- child = child->next;
138
+ attr = reparented->properties;
139
+ while (NULL != attr) {
140
+ relink_namespace((xmlNodePtr)attr);
141
+ attr = attr->next;
139
142
  }
140
143
  }
141
144
  }
@@ -170,7 +173,7 @@ static VALUE
170
173
  reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_reparentee_func prf)
171
174
  {
172
175
  VALUE reparented_obj ;
173
- xmlNodePtr reparentee, pivot, reparented, next_text, new_next_text, parent ;
176
+ xmlNodePtr reparentee, original_reparentee, pivot, reparented, next_text, new_next_text, parent ;
174
177
  int original_ns_prefix_is_default = 0 ;
175
178
 
176
179
  if (!rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlNode)) {
@@ -197,66 +200,66 @@ reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_reparentee_func
197
200
 
198
201
  if (parent) {
199
202
  switch (parent->type) {
200
- case XML_DOCUMENT_NODE:
201
- case XML_HTML_DOCUMENT_NODE:
202
- switch (reparentee->type) {
203
- case XML_ELEMENT_NODE:
204
- case XML_PI_NODE:
205
- case XML_COMMENT_NODE:
206
- case XML_DOCUMENT_TYPE_NODE:
207
- /*
208
- * The DOM specification says no to adding text-like nodes
209
- * directly to a document, but we allow it for compatibility.
210
- */
211
- case XML_TEXT_NODE:
212
- case XML_CDATA_SECTION_NODE:
213
- case XML_ENTITY_REF_NODE:
214
- goto ok;
215
- default:
203
+ case XML_DOCUMENT_NODE:
204
+ case XML_HTML_DOCUMENT_NODE:
205
+ switch (reparentee->type) {
206
+ case XML_ELEMENT_NODE:
207
+ case XML_PI_NODE:
208
+ case XML_COMMENT_NODE:
209
+ case XML_DOCUMENT_TYPE_NODE:
210
+ /*
211
+ * The DOM specification says no to adding text-like nodes
212
+ * directly to a document, but we allow it for compatibility.
213
+ */
214
+ case XML_TEXT_NODE:
215
+ case XML_CDATA_SECTION_NODE:
216
+ case XML_ENTITY_REF_NODE:
217
+ goto ok;
218
+ default:
219
+ break;
220
+ }
216
221
  break;
217
- }
218
- break;
219
- case XML_DOCUMENT_FRAG_NODE:
220
- case XML_ENTITY_REF_NODE:
221
- case XML_ELEMENT_NODE:
222
- switch (reparentee->type) {
223
- case XML_ELEMENT_NODE:
224
- case XML_PI_NODE:
225
- case XML_COMMENT_NODE:
226
- case XML_TEXT_NODE:
227
- case XML_CDATA_SECTION_NODE:
222
+ case XML_DOCUMENT_FRAG_NODE:
228
223
  case XML_ENTITY_REF_NODE:
229
- goto ok;
230
- default:
224
+ case XML_ELEMENT_NODE:
225
+ switch (reparentee->type) {
226
+ case XML_ELEMENT_NODE:
227
+ case XML_PI_NODE:
228
+ case XML_COMMENT_NODE:
229
+ case XML_TEXT_NODE:
230
+ case XML_CDATA_SECTION_NODE:
231
+ case XML_ENTITY_REF_NODE:
232
+ goto ok;
233
+ default:
234
+ break;
235
+ }
236
+ break;
237
+ case XML_ATTRIBUTE_NODE:
238
+ switch (reparentee->type) {
239
+ case XML_TEXT_NODE:
240
+ case XML_ENTITY_REF_NODE:
241
+ goto ok;
242
+ default:
243
+ break;
244
+ }
231
245
  break;
232
- }
233
- break;
234
- case XML_ATTRIBUTE_NODE:
235
- switch (reparentee->type) {
236
246
  case XML_TEXT_NODE:
237
- case XML_ENTITY_REF_NODE:
238
- goto ok;
247
+ /*
248
+ * xmlAddChild() breaks the DOM specification in that it allows
249
+ * adding a text node to another, in which case text nodes are
250
+ * coalesced, but since our JRuby version does not support such
251
+ * operation, we should inhibit it.
252
+ */
253
+ break;
239
254
  default:
240
255
  break;
241
- }
242
- break;
243
- case XML_TEXT_NODE:
244
- /*
245
- * xmlAddChild() breaks the DOM specification in that it allows
246
- * adding a text node to another, in which case text nodes are
247
- * coalesced, but since our JRuby version does not support such
248
- * operation, we should inhibit it.
249
- */
250
- break;
251
- default:
252
- break;
253
256
  }
254
257
 
255
258
  rb_raise(rb_eArgError, "cannot reparent %s there", rb_obj_classname(reparentee_obj));
256
259
  }
257
260
 
258
261
  ok:
259
- xmlUnlinkNode(reparentee);
262
+ original_reparentee = reparentee;
260
263
 
261
264
  if (reparentee->doc != pivot->doc || reparentee->type == XML_TEXT_NODE) {
262
265
  /*
@@ -308,11 +311,13 @@ ok:
308
311
  * issue #391, where new node's prefix may become the string "default"
309
312
  * see libxml2 tree.c xmlNewReconciliedNs which implements this behavior.
310
313
  */
311
- xmlFree((xmlChar *)reparentee->ns->prefix);
314
+ xmlFree(DISCARD_CONST_QUAL_XMLCHAR(reparentee->ns->prefix));
312
315
  reparentee->ns->prefix = NULL;
313
316
  }
314
317
  }
315
318
 
319
+ xmlUnlinkNode(original_reparentee);
320
+
316
321
  if (prf != xmlAddPrevSibling && prf != xmlAddNextSibling
317
322
  && reparentee->type == XML_TEXT_NODE && pivot->next && pivot->next->type == XML_TEXT_NODE) {
318
323
  /*
@@ -357,7 +362,7 @@ ok:
357
362
 
358
363
  reparented_obj = noko_xml_node_wrap(Qnil, reparented);
359
364
 
360
- rb_funcall(reparented_obj, decorate_bang, 0);
365
+ rb_funcall(reparented_obj, id_decorate_bang, 0);
361
366
 
362
367
  return reparented_obj ;
363
368
  }
@@ -936,7 +941,7 @@ get(VALUE self, VALUE rattribute)
936
941
  Data_Get_Struct(self, xmlNode, node);
937
942
  attribute = xmlCharStrdup(StringValueCStr(rattribute));
938
943
 
939
- colon = (xmlChar *)(uintptr_t)xmlStrchr(attribute, (const xmlChar)':');
944
+ colon = DISCARD_CONST_QUAL_XMLCHAR(xmlStrchr(attribute, (const xmlChar)':'));
940
945
  if (colon) {
941
946
  /* split the attribute string into separate prefix and name by
942
947
  * null-terminating the prefix at the colon */
@@ -1292,17 +1297,25 @@ get_name(VALUE self)
1292
1297
  * Returns the path associated with this Node
1293
1298
  */
1294
1299
  static VALUE
1295
- path(VALUE self)
1300
+ noko_xml_node_path(VALUE rb_node)
1296
1301
  {
1297
- xmlNodePtr node;
1298
- xmlChar *path ;
1302
+ xmlNodePtr c_node;
1303
+ xmlChar *c_path ;
1299
1304
  VALUE rval;
1300
1305
 
1301
- Data_Get_Struct(self, xmlNode, node);
1306
+ Data_Get_Struct(rb_node, xmlNode, c_node);
1307
+
1308
+ c_path = xmlGetNodePath(c_node);
1309
+ if (c_path == NULL) {
1310
+ // see https://github.com/sparklemotion/nokogiri/issues/2250
1311
+ // this behavior is clearly undesirable, but is what libxml <= 2.9.10 returned, and so we
1312
+ // do this for now to preserve the behavior across libxml2 versions.
1313
+ rval = NOKOGIRI_STR_NEW2("?");
1314
+ } else {
1315
+ rval = NOKOGIRI_STR_NEW2(c_path);
1316
+ xmlFree(c_path);
1317
+ }
1302
1318
 
1303
- path = xmlGetNodePath(node);
1304
- rval = NOKOGIRI_STR_NEW2(path);
1305
- xmlFree(path);
1306
1319
  return rval ;
1307
1320
  }
1308
1321
 
@@ -1443,6 +1456,7 @@ add_namespace_definition(VALUE rb_node, VALUE rb_prefix, VALUE rb_href)
1443
1456
  * Create a new node with +name+ sharing GC lifecycle with +document+.
1444
1457
  * @param name [String]
1445
1458
  * @param document [Nokogiri::XML::Document]
1459
+ * @yieldparam node [Nokogiri::XML::Node]
1446
1460
  * @return [Nokogiri::XML::Node]
1447
1461
  * @see Nokogiri::XML::Node#initialize
1448
1462
  */
@@ -1632,12 +1646,12 @@ in_context(VALUE self, VALUE _str, VALUE _options)
1632
1646
 
1633
1647
  /* FIXME: This probably needs to handle more constants... */
1634
1648
  switch (error) {
1635
- case XML_ERR_INTERNAL_ERROR:
1636
- case XML_ERR_NO_MEMORY:
1637
- rb_raise(rb_eRuntimeError, "error parsing fragment (%d)", error);
1638
- break;
1639
- default:
1640
- break;
1649
+ case XML_ERR_INTERNAL_ERROR:
1650
+ case XML_ERR_NO_MEMORY:
1651
+ rb_raise(rb_eRuntimeError, "error parsing fragment (%d)", error);
1652
+ break;
1653
+ default:
1654
+ break;
1641
1655
  }
1642
1656
 
1643
1657
  set = xmlXPathNodeSetCreate(NULL);
@@ -1655,85 +1669,83 @@ in_context(VALUE self, VALUE _str, VALUE _options)
1655
1669
 
1656
1670
 
1657
1671
  VALUE
1658
- noko_xml_node_wrap(VALUE klass, xmlNodePtr node)
1672
+ noko_xml_node_wrap(VALUE rb_class, xmlNodePtr c_node)
1659
1673
  {
1660
- VALUE document = Qnil ;
1661
- VALUE node_cache = Qnil ;
1662
- VALUE rb_node = Qnil ;
1674
+ VALUE rb_document, rb_node_cache, rb_node;
1663
1675
  nokogiriTuplePtr node_has_a_document;
1664
- xmlDocPtr doc;
1676
+ xmlDocPtr c_doc;
1665
1677
  void (*mark_method)(xmlNodePtr) = NULL ;
1666
1678
 
1667
- assert(node);
1679
+ assert(c_node);
1668
1680
 
1669
- if (node->type == XML_DOCUMENT_NODE || node->type == XML_HTML_DOCUMENT_NODE) {
1670
- return DOC_RUBY_OBJECT(node->doc);
1681
+ if (c_node->type == XML_DOCUMENT_NODE || c_node->type == XML_HTML_DOCUMENT_NODE) {
1682
+ return DOC_RUBY_OBJECT(c_node->doc);
1671
1683
  }
1672
1684
 
1673
1685
  /* It's OK if the node doesn't have a fully-realized document (as in XML::Reader). */
1674
1686
  /* see https://github.com/sparklemotion/nokogiri/issues/95 */
1675
1687
  /* and https://github.com/sparklemotion/nokogiri/issues/439 */
1676
- doc = node->doc;
1677
- if (doc->type == XML_DOCUMENT_FRAG_NODE) { doc = doc->doc; }
1678
- node_has_a_document = DOC_RUBY_OBJECT_TEST(doc);
1688
+ c_doc = c_node->doc;
1689
+ if (c_doc->type == XML_DOCUMENT_FRAG_NODE) { c_doc = c_doc->doc; }
1690
+ node_has_a_document = DOC_RUBY_OBJECT_TEST(c_doc);
1679
1691
 
1680
- if (node->_private && node_has_a_document) {
1681
- return (VALUE)node->_private;
1692
+ if (c_node->_private && node_has_a_document) {
1693
+ return (VALUE)c_node->_private;
1682
1694
  }
1683
1695
 
1684
- if (!RTEST(klass)) {
1685
- switch (node->type) {
1686
- case XML_ELEMENT_NODE:
1687
- klass = cNokogiriXmlElement;
1688
- break;
1689
- case XML_TEXT_NODE:
1690
- klass = cNokogiriXmlText;
1691
- break;
1692
- case XML_ATTRIBUTE_NODE:
1693
- klass = cNokogiriXmlAttr;
1694
- break;
1695
- case XML_ENTITY_REF_NODE:
1696
- klass = cNokogiriXmlEntityReference;
1697
- break;
1698
- case XML_COMMENT_NODE:
1699
- klass = cNokogiriXmlComment;
1700
- break;
1701
- case XML_DOCUMENT_FRAG_NODE:
1702
- klass = cNokogiriXmlDocumentFragment;
1703
- break;
1704
- case XML_PI_NODE:
1705
- klass = cNokogiriXmlProcessingInstruction;
1706
- break;
1707
- case XML_ENTITY_DECL:
1708
- klass = cNokogiriXmlEntityDecl;
1709
- break;
1710
- case XML_CDATA_SECTION_NODE:
1711
- klass = cNokogiriXmlCData;
1712
- break;
1713
- case XML_DTD_NODE:
1714
- klass = cNokogiriXmlDtd;
1715
- break;
1716
- case XML_ATTRIBUTE_DECL:
1717
- klass = cNokogiriXmlAttributeDecl;
1718
- break;
1719
- case XML_ELEMENT_DECL:
1720
- klass = cNokogiriXmlElementDecl;
1721
- break;
1722
- default:
1723
- klass = cNokogiriXmlNode;
1696
+ if (!RTEST(rb_class)) {
1697
+ switch (c_node->type) {
1698
+ case XML_ELEMENT_NODE:
1699
+ rb_class = cNokogiriXmlElement;
1700
+ break;
1701
+ case XML_TEXT_NODE:
1702
+ rb_class = cNokogiriXmlText;
1703
+ break;
1704
+ case XML_ATTRIBUTE_NODE:
1705
+ rb_class = cNokogiriXmlAttr;
1706
+ break;
1707
+ case XML_ENTITY_REF_NODE:
1708
+ rb_class = cNokogiriXmlEntityReference;
1709
+ break;
1710
+ case XML_COMMENT_NODE:
1711
+ rb_class = cNokogiriXmlComment;
1712
+ break;
1713
+ case XML_DOCUMENT_FRAG_NODE:
1714
+ rb_class = cNokogiriXmlDocumentFragment;
1715
+ break;
1716
+ case XML_PI_NODE:
1717
+ rb_class = cNokogiriXmlProcessingInstruction;
1718
+ break;
1719
+ case XML_ENTITY_DECL:
1720
+ rb_class = cNokogiriXmlEntityDecl;
1721
+ break;
1722
+ case XML_CDATA_SECTION_NODE:
1723
+ rb_class = cNokogiriXmlCData;
1724
+ break;
1725
+ case XML_DTD_NODE:
1726
+ rb_class = cNokogiriXmlDtd;
1727
+ break;
1728
+ case XML_ATTRIBUTE_DECL:
1729
+ rb_class = cNokogiriXmlAttributeDecl;
1730
+ break;
1731
+ case XML_ELEMENT_DECL:
1732
+ rb_class = cNokogiriXmlElementDecl;
1733
+ break;
1734
+ default:
1735
+ rb_class = cNokogiriXmlNode;
1724
1736
  }
1725
1737
  }
1726
1738
 
1727
1739
  mark_method = node_has_a_document ? mark : NULL ;
1728
1740
 
1729
- rb_node = Data_Wrap_Struct(klass, mark_method, debug_node_dealloc, node) ;
1730
- node->_private = (void *)rb_node;
1741
+ rb_node = Data_Wrap_Struct(rb_class, mark_method, debug_node_dealloc, c_node) ;
1742
+ c_node->_private = (void *)rb_node;
1731
1743
 
1732
1744
  if (node_has_a_document) {
1733
- document = DOC_RUBY_OBJECT(doc);
1734
- node_cache = DOC_NODE_CACHE(doc);
1735
- rb_ary_push(node_cache, rb_node);
1736
- rb_funcall(document, decorate, 1, rb_node);
1745
+ rb_document = DOC_RUBY_OBJECT(c_doc);
1746
+ rb_node_cache = DOC_NODE_CACHE(c_doc);
1747
+ rb_ary_push(rb_node_cache, rb_node);
1748
+ rb_funcall(rb_document, id_decorate, 1, rb_node);
1737
1749
  }
1738
1750
 
1739
1751
  return rb_node ;
@@ -1763,6 +1775,8 @@ noko_init_xml_node()
1763
1775
  {
1764
1776
  cNokogiriXmlNode = rb_define_class_under(mNokogiriXml, "Node", rb_cObject);
1765
1777
 
1778
+ rb_undef_alloc_func(cNokogiriXmlNode);
1779
+
1766
1780
  rb_define_singleton_method(cNokogiriXmlNode, "new", rb_xml_node_new, -1);
1767
1781
 
1768
1782
  rb_define_method(cNokogiriXmlNode, "add_namespace_definition", add_namespace_definition, 2);
@@ -1780,7 +1794,7 @@ noko_init_xml_node()
1780
1794
  rb_define_method(cNokogiriXmlNode, "next_element", next_element, 0);
1781
1795
  rb_define_method(cNokogiriXmlNode, "previous_element", previous_element, 0);
1782
1796
  rb_define_method(cNokogiriXmlNode, "node_type", node_type, 0);
1783
- rb_define_method(cNokogiriXmlNode, "path", path, 0);
1797
+ rb_define_method(cNokogiriXmlNode, "path", noko_xml_node_path, 0);
1784
1798
  rb_define_method(cNokogiriXmlNode, "key?", key_eh, 1);
1785
1799
  rb_define_method(cNokogiriXmlNode, "namespaced_key?", namespaced_key_eh, 2);
1786
1800
  rb_define_method(cNokogiriXmlNode, "blank?", blank_eh, 0);
@@ -1818,8 +1832,8 @@ noko_init_xml_node()
1818
1832
  rb_define_private_method(cNokogiriXmlNode, "set_namespace", set_namespace, 1);
1819
1833
  rb_define_private_method(cNokogiriXmlNode, "compare", compare, 1);
1820
1834
 
1821
- decorate = rb_intern("decorate");
1822
- decorate_bang = rb_intern("decorate!");
1835
+ id_decorate = rb_intern("decorate");
1836
+ id_decorate_bang = rb_intern("decorate!");
1823
1837
  }
1824
1838
 
1825
1839
  /* vim: set noet sw=4 sws=4 */
@@ -20,20 +20,20 @@ ruby_object_get(xmlNodePtr c_node)
20
20
  {
21
21
  /* see xmlElementType in libxml2 tree.h */
22
22
  switch (c_node->type) {
23
- case XML_NAMESPACE_DECL:
24
- /* _private is later in the namespace struct */
25
- return (VALUE)(((xmlNsPtr)c_node)->_private);
26
-
27
- case XML_DOCUMENT_NODE:
28
- case XML_HTML_DOCUMENT_NODE:
29
- /* in documents we use _private to store a tuple */
30
- if (DOC_RUBY_OBJECT_TEST(((xmlDocPtr)c_node))) {
31
- return DOC_RUBY_OBJECT((xmlDocPtr)c_node);
32
- }
33
- return (VALUE)NULL;
34
-
35
- default:
36
- return (VALUE)(c_node->_private);
23
+ case XML_NAMESPACE_DECL:
24
+ /* _private is later in the namespace struct */
25
+ return (VALUE)(((xmlNsPtr)c_node)->_private);
26
+
27
+ case XML_DOCUMENT_NODE:
28
+ case XML_HTML_DOCUMENT_NODE:
29
+ /* in documents we use _private to store a tuple */
30
+ if (DOC_RUBY_OBJECT_TEST(((xmlDocPtr)c_node))) {
31
+ return DOC_RUBY_OBJECT((xmlDocPtr)c_node);
32
+ }
33
+ return (VALUE)NULL;
34
+
35
+ default:
36
+ return (VALUE)(c_node->_private);
37
37
  }
38
38
  }
39
39
 
@@ -373,12 +373,12 @@ slice(int argc, VALUE *argv, VALUE self)
373
373
 
374
374
  /* if arg is Range */
375
375
  switch (rb_range_beg_len(arg, &beg, &len, (long)node_set->nodeNr, 0)) {
376
- case Qfalse:
377
- break;
378
- case Qnil:
379
- return Qnil;
380
- default:
381
- return subseq(self, beg, len);
376
+ case Qfalse:
377
+ break;
378
+ case Qnil:
379
+ return Qnil;
380
+ default:
381
+ return subseq(self, beg, len);
382
382
  }
383
383
 
384
384
  return index_at(self, NUM2LONG(arg));
@@ -662,6 +662,8 @@ noko_init_xml_reader()
662
662
  */
663
663
  cNokogiriXmlReader = rb_define_class_under(mNokogiriXml, "Reader", rb_cObject);
664
664
 
665
+ rb_undef_alloc_func(cNokogiriXmlReader);
666
+
665
667
  rb_define_singleton_method(cNokogiriXmlReader, "from_memory", from_memory, -1);
666
668
  rb_define_singleton_method(cNokogiriXmlReader, "from_io", from_io, -1);
667
669
 
@@ -30,12 +30,12 @@ start_document(void *ctx)
30
30
  version = ctxt->version ? NOKOGIRI_STR_NEW2(ctxt->version) : Qnil;
31
31
 
32
32
  switch (ctxt->standalone) {
33
- case 0:
34
- standalone = NOKOGIRI_STR_NEW2("no");
35
- break;
36
- case 1:
37
- standalone = NOKOGIRI_STR_NEW2("yes");
38
- break;
33
+ case 0:
34
+ standalone = NOKOGIRI_STR_NEW2("no");
35
+ break;
36
+ case 1:
37
+ standalone = NOKOGIRI_STR_NEW2("yes");
38
+ break;
39
39
  }
40
40
 
41
41
  rb_funcall(doc, id_xmldecl, 3, version, encoding, standalone);
@@ -265,6 +265,8 @@ noko_init_xml_sax_parser_context()
265
265
  {
266
266
  cNokogiriXmlSaxParserContext = rb_define_class_under(mNokogiriXmlSax, "ParserContext", rb_cObject);
267
267
 
268
+ rb_undef_alloc_func(cNokogiriXmlSaxParserContext);
269
+
268
270
  rb_define_singleton_method(cNokogiriXmlSaxParserContext, "io", parse_io, 2);
269
271
  rb_define_singleton_method(cNokogiriXmlSaxParserContext, "memory", parse_memory, 1);
270
272
  rb_define_singleton_method(cNokogiriXmlSaxParserContext, "file", parse_file, 1);
@@ -274,6 +274,8 @@ noko_init_xml_schema()
274
274
  {
275
275
  cNokogiriXmlSchema = rb_define_class_under(mNokogiriXml, "Schema", rb_cObject);
276
276
 
277
+ rb_undef_alloc_func(cNokogiriXmlSchema);
278
+
277
279
  rb_define_singleton_method(cNokogiriXmlSchema, "read_memory", read_memory, -1);
278
280
  rb_define_singleton_method(cNokogiriXmlSchema, "from_document", from_document, -1);
279
281