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.
- checksums.yaml +4 -4
- data/LICENSE-DEPENDENCIES.md +243 -22
- data/LICENSE.md +1 -1
- data/README.md +7 -6
- data/dependencies.yml +12 -12
- data/ext/nokogiri/depend +35 -34
- data/ext/nokogiri/extconf.rb +185 -103
- data/ext/nokogiri/gumbo.c +584 -0
- data/ext/nokogiri/{html_document.c → html4_document.c} +8 -8
- data/ext/nokogiri/{html_element_description.c → html4_element_description.c} +21 -19
- data/ext/nokogiri/{html_entity_lookup.c → html4_entity_lookup.c} +7 -7
- data/ext/nokogiri/{html_sax_parser_context.c → html4_sax_parser_context.c} +6 -5
- data/ext/nokogiri/{html_sax_push_parser.c → html4_sax_push_parser.c} +4 -4
- data/ext/nokogiri/libxml2_backwards_compat.c +30 -30
- data/ext/nokogiri/nokogiri.c +70 -38
- data/ext/nokogiri/nokogiri.h +19 -9
- data/ext/nokogiri/xml_document.c +50 -49
- data/ext/nokogiri/xml_element_content.c +2 -0
- data/ext/nokogiri/xml_encoding_handler.c +11 -6
- data/ext/nokogiri/xml_namespace.c +4 -2
- data/ext/nokogiri/xml_node.c +147 -133
- data/ext/nokogiri/xml_node_set.c +20 -20
- data/ext/nokogiri/xml_reader.c +2 -0
- data/ext/nokogiri/xml_sax_parser.c +6 -6
- data/ext/nokogiri/xml_sax_parser_context.c +2 -0
- data/ext/nokogiri/xml_schema.c +2 -0
- data/ext/nokogiri/xml_xpath_context.c +67 -65
- data/ext/nokogiri/xslt_stylesheet.c +2 -1
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +101 -0
- data/gumbo-parser/THANKS +27 -0
- data/gumbo-parser/src/Makefile +34 -0
- data/gumbo-parser/src/README.md +41 -0
- data/gumbo-parser/src/ascii.c +75 -0
- data/gumbo-parser/src/ascii.h +115 -0
- data/gumbo-parser/src/attribute.c +42 -0
- data/gumbo-parser/src/attribute.h +17 -0
- data/gumbo-parser/src/char_ref.c +22225 -0
- data/gumbo-parser/src/char_ref.h +29 -0
- data/gumbo-parser/src/char_ref.rl +2154 -0
- data/gumbo-parser/src/error.c +626 -0
- data/gumbo-parser/src/error.h +148 -0
- data/gumbo-parser/src/foreign_attrs.c +104 -0
- data/gumbo-parser/src/foreign_attrs.gperf +27 -0
- data/gumbo-parser/src/gumbo.h +943 -0
- data/gumbo-parser/src/insertion_mode.h +33 -0
- data/gumbo-parser/src/macros.h +91 -0
- data/gumbo-parser/src/parser.c +4886 -0
- data/gumbo-parser/src/parser.h +41 -0
- data/gumbo-parser/src/replacement.h +33 -0
- data/gumbo-parser/src/string_buffer.c +103 -0
- data/gumbo-parser/src/string_buffer.h +68 -0
- data/gumbo-parser/src/string_piece.c +48 -0
- data/gumbo-parser/src/svg_attrs.c +174 -0
- data/gumbo-parser/src/svg_attrs.gperf +77 -0
- data/gumbo-parser/src/svg_tags.c +137 -0
- data/gumbo-parser/src/svg_tags.gperf +55 -0
- data/gumbo-parser/src/tag.c +222 -0
- data/gumbo-parser/src/tag_lookup.c +382 -0
- data/gumbo-parser/src/tag_lookup.gperf +169 -0
- data/gumbo-parser/src/tag_lookup.h +13 -0
- data/gumbo-parser/src/token_buffer.c +79 -0
- data/gumbo-parser/src/token_buffer.h +71 -0
- data/gumbo-parser/src/token_type.h +17 -0
- data/gumbo-parser/src/tokenizer.c +3463 -0
- data/gumbo-parser/src/tokenizer.h +112 -0
- data/gumbo-parser/src/tokenizer_states.h +339 -0
- data/gumbo-parser/src/utf8.c +245 -0
- data/gumbo-parser/src/utf8.h +164 -0
- data/gumbo-parser/src/util.c +68 -0
- data/gumbo-parser/src/util.h +30 -0
- data/gumbo-parser/src/vector.c +111 -0
- data/gumbo-parser/src/vector.h +45 -0
- data/lib/nokogiri/css/parser.rb +1 -1
- data/lib/nokogiri/css/parser.y +1 -1
- data/lib/nokogiri/css/syntax_error.rb +1 -1
- data/lib/nokogiri/css.rb +14 -14
- data/lib/nokogiri/extension.rb +7 -2
- data/lib/nokogiri/gumbo.rb +14 -0
- data/lib/nokogiri/html.rb +31 -27
- data/lib/nokogiri/{html → html4}/builder.rb +2 -2
- data/lib/nokogiri/{html → html4}/document.rb +4 -4
- data/lib/nokogiri/{html → html4}/document_fragment.rb +3 -3
- data/lib/nokogiri/{html → html4}/element_description.rb +1 -1
- data/lib/nokogiri/{html → html4}/element_description_defaults.rb +1 -1
- data/lib/nokogiri/{html → html4}/entity_lookup.rb +1 -1
- data/lib/nokogiri/{html → html4}/sax/parser.rb +11 -14
- data/lib/nokogiri/html4/sax/parser_context.rb +19 -0
- data/lib/nokogiri/{html → html4}/sax/push_parser.rb +5 -5
- data/lib/nokogiri/html4.rb +40 -0
- data/lib/nokogiri/html5/document.rb +74 -0
- data/lib/nokogiri/html5/document_fragment.rb +80 -0
- data/lib/nokogiri/html5/node.rb +93 -0
- data/lib/nokogiri/html5.rb +473 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +12 -2
- data/lib/nokogiri/xml/builder.rb +38 -0
- data/lib/nokogiri/xml/document.rb +89 -17
- data/lib/nokogiri/xml/node/save_options.rb +1 -1
- data/lib/nokogiri/xml/node.rb +7 -5
- data/lib/nokogiri/xml/parse_options.rb +2 -0
- data/lib/nokogiri/xml/pp.rb +2 -2
- data/lib/nokogiri/xml/sax/document.rb +24 -30
- data/lib/nokogiri/xml/sax.rb +4 -4
- data/lib/nokogiri/xml/xpath.rb +2 -2
- data/lib/nokogiri/xml.rb +35 -36
- data/lib/nokogiri/xslt/stylesheet.rb +1 -1
- data/lib/nokogiri/xslt.rb +16 -16
- data/lib/nokogiri.rb +31 -29
- data/patches/libxml2/{0002-Remove-script-macro-support.patch → 0001-Remove-script-macro-support.patch} +0 -0
- data/patches/libxml2/{0003-Update-entities-to-remove-handling-of-ssi.patch → 0002-Update-entities-to-remove-handling-of-ssi.patch} +0 -0
- data/patches/libxml2/{0004-libxml2.la-is-in-top_builddir.patch → 0003-libxml2.la-is-in-top_builddir.patch} +1 -1
- data/patches/libxml2/{0008-use-glibc-strlen.patch → 0004-use-glibc-strlen.patch} +0 -0
- data/patches/libxml2/{0009-avoid-isnan-isinf.patch → 0005-avoid-isnan-isinf.patch} +4 -4
- data/patches/libxml2/0006-update-automake-files-for-arm64.patch +2511 -0
- data/patches/libxml2/0007-Fix-XPath-recursion-limit.patch +31 -0
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2511 -0
- data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +19 -0
- data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
- metadata +110 -69
- data/lib/nokogiri/html/sax/parser_context.rb +0 -17
- data/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch +0 -78
- data/patches/libxml2/0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch +0 -32
- data/patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch +0 -73
- data/patches/libxml2/0007-use-new-htmlParseLookupCommentEnd-to-find-comment-en.patch +0 -103
- data/patches/libxml2/0010-parser.c-shrink-the-input-buffer-when-appropriate.patch +0 -70
- data/ports/archives/libxml2-2.9.10.tar.gz +0 -0
data/ext/nokogiri/xml_node.c
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
VALUE cNokogiriXmlNode ;
|
4
4
|
|
5
|
-
static ID
|
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 &&
|
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
|
-
|
136
|
-
while (NULL !=
|
137
|
-
relink_namespace(
|
138
|
-
|
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
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
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
|
-
|
230
|
-
|
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
|
-
|
238
|
-
|
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
|
-
|
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((
|
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,
|
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 = (
|
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
|
-
|
1300
|
+
noko_xml_node_path(VALUE rb_node)
|
1296
1301
|
{
|
1297
|
-
xmlNodePtr
|
1298
|
-
xmlChar *
|
1302
|
+
xmlNodePtr c_node;
|
1303
|
+
xmlChar *c_path ;
|
1299
1304
|
VALUE rval;
|
1300
1305
|
|
1301
|
-
Data_Get_Struct(
|
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
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
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
|
1672
|
+
noko_xml_node_wrap(VALUE rb_class, xmlNodePtr c_node)
|
1659
1673
|
{
|
1660
|
-
VALUE
|
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
|
1676
|
+
xmlDocPtr c_doc;
|
1665
1677
|
void (*mark_method)(xmlNodePtr) = NULL ;
|
1666
1678
|
|
1667
|
-
assert(
|
1679
|
+
assert(c_node);
|
1668
1680
|
|
1669
|
-
if (
|
1670
|
-
return DOC_RUBY_OBJECT(
|
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
|
-
|
1677
|
-
if (
|
1678
|
-
node_has_a_document = DOC_RUBY_OBJECT_TEST(
|
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 (
|
1681
|
-
return (VALUE)
|
1692
|
+
if (c_node->_private && node_has_a_document) {
|
1693
|
+
return (VALUE)c_node->_private;
|
1682
1694
|
}
|
1683
1695
|
|
1684
|
-
if (!RTEST(
|
1685
|
-
switch (
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
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(
|
1730
|
-
|
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
|
-
|
1734
|
-
|
1735
|
-
rb_ary_push(
|
1736
|
-
rb_funcall(
|
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",
|
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
|
-
|
1822
|
-
|
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 */
|
data/ext/nokogiri/xml_node_set.c
CHANGED
@@ -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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
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));
|
data/ext/nokogiri/xml_reader.c
CHANGED
@@ -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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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);
|
data/ext/nokogiri/xml_schema.c
CHANGED
@@ -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
|
|