nokogiri 1.14.3 → 1.15.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/Gemfile +9 -8
- data/dependencies.yml +7 -6
- data/ext/nokogiri/extconf.rb +66 -22
- data/ext/nokogiri/html4_document.c +1 -2
- data/ext/nokogiri/html4_element_description.c +19 -14
- data/ext/nokogiri/html4_sax_parser_context.c +10 -16
- data/ext/nokogiri/html4_sax_push_parser.c +2 -2
- data/ext/nokogiri/nokogiri.c +46 -24
- data/ext/nokogiri/nokogiri.h +13 -2
- data/ext/nokogiri/xml_attr.c +1 -1
- data/ext/nokogiri/xml_cdata.c +31 -17
- data/ext/nokogiri/xml_comment.c +1 -1
- data/ext/nokogiri/xml_document.c +106 -22
- data/ext/nokogiri/xml_document_fragment.c +1 -1
- data/ext/nokogiri/xml_dtd.c +1 -1
- data/ext/nokogiri/xml_element_content.c +32 -29
- data/ext/nokogiri/xml_element_decl.c +5 -5
- data/ext/nokogiri/xml_encoding_handler.c +12 -4
- data/ext/nokogiri/xml_entity_reference.c +1 -1
- data/ext/nokogiri/xml_namespace.c +11 -12
- data/ext/nokogiri/xml_node.c +8 -8
- data/ext/nokogiri/xml_node_set.c +125 -105
- data/ext/nokogiri/xml_processing_instruction.c +1 -1
- data/ext/nokogiri/xml_reader.c +37 -28
- data/ext/nokogiri/xml_relax_ng.c +65 -78
- data/ext/nokogiri/xml_sax_parser.c +24 -5
- data/ext/nokogiri/xml_sax_parser_context.c +46 -25
- data/ext/nokogiri/xml_sax_push_parser.c +29 -8
- data/ext/nokogiri/xml_schema.c +94 -114
- data/ext/nokogiri/xml_text.c +27 -13
- data/ext/nokogiri/xml_xpath_context.c +156 -83
- data/ext/nokogiri/xslt_stylesheet.c +103 -50
- data/gumbo-parser/src/error.c +8 -4
- data/gumbo-parser/src/foreign_attrs.c +13 -14
- data/gumbo-parser/src/foreign_attrs.gperf +1 -1
- data/gumbo-parser/src/parser.c +13 -0
- data/lib/nokogiri/css/xpath_visitor.rb +2 -2
- data/lib/nokogiri/extension.rb +1 -1
- data/lib/nokogiri/html4/document_fragment.rb +1 -1
- data/lib/nokogiri/html4/element_description_defaults.rb +1821 -353
- data/lib/nokogiri/html5/document_fragment.rb +1 -1
- data/lib/nokogiri/html5/node.rb +5 -0
- data/lib/nokogiri/html5.rb +5 -2
- data/lib/nokogiri/jruby/nokogiri_jars.rb +9 -9
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/xml/attribute_decl.rb +4 -2
- data/lib/nokogiri/xml/document.rb +1 -2
- data/lib/nokogiri/xml/document_fragment.rb +1 -1
- data/lib/nokogiri/xml/element_content.rb +10 -2
- data/lib/nokogiri/xml/element_decl.rb +4 -2
- data/lib/nokogiri/xml/entity_decl.rb +4 -2
- data/lib/nokogiri/xml/node/save_options.rb +8 -0
- data/lib/nokogiri/xml/node.rb +22 -13
- data/lib/nokogiri/xml/pp/node.rb +23 -12
- data/lib/nokogiri/xml/sax/document.rb +1 -1
- data/lib/nokogiri/xml/searchable.rb +18 -10
- data/lib/nokogiri/xslt.rb +73 -3
- data/lib/nokogiri.rb +12 -4
- data/lib/xsd/xmlparser/nokogiri.rb +1 -1
- data/patches/libxml2/0010-update-config.guess-and-config.sub-for-libxml2.patch +224 -0
- data/patches/libxml2/0011-rip-out-libxml2-s-libc_single_threaded-support.patch +30 -0
- data/patches/libxslt/0001-update-config.guess-and-config.sub-for-libxslt.patch +224 -0
- data/ports/archives/libxml2-2.11.6.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.39.tar.xz +0 -0
- metadata +10 -8
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +0 -3037
- data/ports/archives/libxml2-2.10.4.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.37.tar.xz +0 -0
data/ext/nokogiri/xml_document.c
CHANGED
@@ -51,8 +51,9 @@ remove_private(xmlNodePtr node)
|
|
51
51
|
}
|
52
52
|
|
53
53
|
static void
|
54
|
-
mark(
|
54
|
+
mark(void *data)
|
55
55
|
{
|
56
|
+
xmlDocPtr doc = (xmlDocPtr)data;
|
56
57
|
nokogiriTuplePtr tuple = (nokogiriTuplePtr)doc->_private;
|
57
58
|
if (tuple) {
|
58
59
|
rb_gc_mark(tuple->doc);
|
@@ -61,8 +62,9 @@ mark(xmlDocPtr doc)
|
|
61
62
|
}
|
62
63
|
|
63
64
|
static void
|
64
|
-
dealloc(
|
65
|
+
dealloc(void *data)
|
65
66
|
{
|
67
|
+
xmlDocPtr doc = (xmlDocPtr)data;
|
66
68
|
st_table *node_hash;
|
67
69
|
|
68
70
|
node_hash = DOC_UNLINKED_NODE_HASH(doc);
|
@@ -72,18 +74,71 @@ dealloc(xmlDocPtr doc)
|
|
72
74
|
|
73
75
|
ruby_xfree(doc->_private);
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
*
|
77
|
+
#pragma GCC diagnostic push
|
78
|
+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" // xmlDeregisterNodeDefault is deprecated as of libxml2 2.11.0
|
79
|
+
/*
|
80
|
+
* libxml-ruby < 3.0.0 uses xmlDeregisterNodeDefault. If the user is using one of those older
|
81
|
+
* versions, the registered callback from libxml-ruby will access the _private pointers set by
|
82
|
+
* nokogiri, which will result in segfaults.
|
83
|
+
*
|
84
|
+
* To avoid this, we need to clear the _private pointers from all nodes in this document tree
|
85
|
+
* before that callback gets invoked.
|
86
|
+
*
|
87
|
+
* libxml-ruby 3.0.0 was released in 2017-02, so at some point we can probably safely remove this
|
88
|
+
* safeguard (though probably pairing with a runtime check on the libxml-ruby version).
|
79
89
|
*/
|
80
90
|
if (xmlDeregisterNodeDefaultValue) {
|
81
91
|
remove_private((xmlNodePtr)doc);
|
82
92
|
}
|
93
|
+
#pragma GCC diagnostic pop
|
83
94
|
|
84
95
|
xmlFreeDoc(doc);
|
85
96
|
}
|
86
97
|
|
98
|
+
static size_t
|
99
|
+
memsize_node(const xmlNodePtr node)
|
100
|
+
{
|
101
|
+
/* note we don't count namespace definitions, just going for a good-enough number here */
|
102
|
+
xmlNodePtr child;
|
103
|
+
xmlAttrPtr property;
|
104
|
+
size_t memsize = 0;
|
105
|
+
|
106
|
+
memsize += xmlStrlen(node->name);
|
107
|
+
|
108
|
+
if (node->type == XML_ELEMENT_NODE) {
|
109
|
+
for (property = node->properties; property; property = property->next) {
|
110
|
+
memsize += sizeof(xmlAttr) + memsize_node((xmlNodePtr)property);
|
111
|
+
}
|
112
|
+
}
|
113
|
+
if (node->type == XML_TEXT_NODE) {
|
114
|
+
memsize += xmlStrlen(node->content);
|
115
|
+
}
|
116
|
+
for (child = node->children; child; child = child->next) {
|
117
|
+
memsize += sizeof(xmlNode) + memsize_node(child);
|
118
|
+
}
|
119
|
+
return memsize;
|
120
|
+
}
|
121
|
+
|
122
|
+
static size_t
|
123
|
+
memsize(const void *data)
|
124
|
+
{
|
125
|
+
xmlDocPtr doc = (const xmlDocPtr)data;
|
126
|
+
size_t memsize = sizeof(xmlDoc);
|
127
|
+
/* This may not account for all memory use */
|
128
|
+
memsize += memsize_node((xmlNodePtr)doc);
|
129
|
+
return memsize;
|
130
|
+
}
|
131
|
+
|
132
|
+
static const rb_data_type_t noko_xml_document_data_type = {
|
133
|
+
.wrap_struct_name = "Nokogiri::XML::Document",
|
134
|
+
.function = {
|
135
|
+
.dmark = mark,
|
136
|
+
.dfree = dealloc,
|
137
|
+
.dsize = memsize,
|
138
|
+
},
|
139
|
+
// .flags = RUBY_TYPED_FREE_IMMEDIATELY, // TODO see https://github.com/sparklemotion/nokogiri/issues/2822
|
140
|
+
};
|
141
|
+
|
87
142
|
static void
|
88
143
|
recursively_remove_namespaces_from_node(xmlNodePtr node)
|
89
144
|
{
|
@@ -126,8 +181,7 @@ recursively_remove_namespaces_from_node(xmlNodePtr node)
|
|
126
181
|
static VALUE
|
127
182
|
url(VALUE self)
|
128
183
|
{
|
129
|
-
xmlDocPtr doc;
|
130
|
-
Data_Get_Struct(self, xmlDoc, doc);
|
184
|
+
xmlDocPtr doc = noko_xml_document_unwrap(self);
|
131
185
|
|
132
186
|
if (doc->URL) { return NOKOGIRI_STR_NEW2(doc->URL); }
|
133
187
|
|
@@ -146,7 +200,7 @@ rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
|
|
146
200
|
xmlDocPtr c_document;
|
147
201
|
xmlNodePtr c_new_root = NULL, c_current_root;
|
148
202
|
|
149
|
-
|
203
|
+
c_document = noko_xml_document_unwrap(self);
|
150
204
|
|
151
205
|
c_current_root = xmlDocGetRootElement(c_document);
|
152
206
|
if (c_current_root) {
|
@@ -190,7 +244,7 @@ rb_xml_document_root(VALUE self)
|
|
190
244
|
xmlDocPtr c_document;
|
191
245
|
xmlNodePtr c_root;
|
192
246
|
|
193
|
-
|
247
|
+
c_document = noko_xml_document_unwrap(self);
|
194
248
|
|
195
249
|
c_root = xmlDocGetRootElement(c_document);
|
196
250
|
if (!c_root) {
|
@@ -209,8 +263,7 @@ rb_xml_document_root(VALUE self)
|
|
209
263
|
static VALUE
|
210
264
|
set_encoding(VALUE self, VALUE encoding)
|
211
265
|
{
|
212
|
-
xmlDocPtr doc;
|
213
|
-
Data_Get_Struct(self, xmlDoc, doc);
|
266
|
+
xmlDocPtr doc = noko_xml_document_unwrap(self);
|
214
267
|
|
215
268
|
if (doc->encoding) {
|
216
269
|
xmlFree(DISCARD_CONST_QUAL_XMLCHAR(doc->encoding));
|
@@ -230,8 +283,7 @@ set_encoding(VALUE self, VALUE encoding)
|
|
230
283
|
static VALUE
|
231
284
|
encoding(VALUE self)
|
232
285
|
{
|
233
|
-
xmlDocPtr doc;
|
234
|
-
Data_Get_Struct(self, xmlDoc, doc);
|
286
|
+
xmlDocPtr doc = noko_xml_document_unwrap(self);
|
235
287
|
|
236
288
|
if (!doc->encoding) { return Qnil; }
|
237
289
|
return NOKOGIRI_STR_NEW2(doc->encoding);
|
@@ -246,8 +298,7 @@ encoding(VALUE self)
|
|
246
298
|
static VALUE
|
247
299
|
version(VALUE self)
|
248
300
|
{
|
249
|
-
xmlDocPtr doc;
|
250
|
-
Data_Get_Struct(self, xmlDoc, doc);
|
301
|
+
xmlDocPtr doc = noko_xml_document_unwrap(self);
|
251
302
|
|
252
303
|
if (!doc->version) { return Qnil; }
|
253
304
|
return NOKOGIRI_STR_NEW2(doc->version);
|
@@ -369,7 +420,7 @@ duplicate_document(int argc, VALUE *argv, VALUE self)
|
|
369
420
|
level = INT2NUM((long)1);
|
370
421
|
}
|
371
422
|
|
372
|
-
|
423
|
+
doc = noko_xml_document_unwrap(self);
|
373
424
|
|
374
425
|
dup = xmlCopyDoc(doc, (int)NUM2INT(level));
|
375
426
|
|
@@ -442,8 +493,7 @@ new (int argc, VALUE *argv, VALUE klass)
|
|
442
493
|
static VALUE
|
443
494
|
remove_namespaces_bang(VALUE self)
|
444
495
|
{
|
445
|
-
xmlDocPtr doc ;
|
446
|
-
Data_Get_Struct(self, xmlDoc, doc);
|
496
|
+
xmlDocPtr doc = noko_xml_document_unwrap(self);
|
447
497
|
|
448
498
|
recursively_remove_namespaces_from_node((xmlNodePtr)doc);
|
449
499
|
return self;
|
@@ -471,7 +521,7 @@ create_entity(int argc, VALUE *argv, VALUE self)
|
|
471
521
|
xmlEntityPtr ptr;
|
472
522
|
xmlDocPtr doc ;
|
473
523
|
|
474
|
-
|
524
|
+
doc = noko_xml_document_unwrap(self);
|
475
525
|
|
476
526
|
rb_scan_args(argc, argv, "14", &name, &type, &external_id, &system_id,
|
477
527
|
&content);
|
@@ -559,7 +609,7 @@ rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
|
|
559
609
|
}
|
560
610
|
}
|
561
611
|
|
562
|
-
|
612
|
+
c_doc = noko_xml_document_unwrap(self);
|
563
613
|
|
564
614
|
rb_cStringIO = rb_const_get_at(rb_cObject, rb_intern("StringIO"));
|
565
615
|
rb_io = rb_class_new_instance(0, 0, rb_cStringIO);
|
@@ -607,7 +657,7 @@ noko_xml_document_wrap_with_init_args(VALUE klass, xmlDocPtr c_document, int arg
|
|
607
657
|
klass = cNokogiriXmlDocument;
|
608
658
|
}
|
609
659
|
|
610
|
-
rb_document =
|
660
|
+
rb_document = TypedData_Wrap_Struct(klass, &noko_xml_document_data_type, c_document);
|
611
661
|
|
612
662
|
tuple = (nokogiriTuplePtr)ruby_xmalloc(sizeof(nokogiriTuple));
|
613
663
|
tuple->doc = rb_document;
|
@@ -640,6 +690,40 @@ noko_xml_document_wrap(VALUE klass, xmlDocPtr doc)
|
|
640
690
|
return noko_xml_document_wrap_with_init_args(klass, doc, 0, NULL);
|
641
691
|
}
|
642
692
|
|
693
|
+
xmlDocPtr
|
694
|
+
noko_xml_document_unwrap(VALUE rb_document)
|
695
|
+
{
|
696
|
+
xmlDocPtr c_document;
|
697
|
+
TypedData_Get_Struct(rb_document, xmlDoc, &noko_xml_document_data_type, c_document);
|
698
|
+
return c_document;
|
699
|
+
}
|
700
|
+
|
701
|
+
/* Schema creation will remove and deallocate "blank" nodes.
|
702
|
+
* If those blank nodes have been exposed to Ruby, they could get freed
|
703
|
+
* out from under the VALUE pointer. This function checks to see if any of
|
704
|
+
* those nodes have been exposed to Ruby, and if so we should raise an exception.
|
705
|
+
*/
|
706
|
+
int
|
707
|
+
noko_xml_document_has_wrapped_blank_nodes_p(xmlDocPtr c_document)
|
708
|
+
{
|
709
|
+
VALUE cache = DOC_NODE_CACHE(c_document);
|
710
|
+
|
711
|
+
if (NIL_P(cache)) {
|
712
|
+
return 0;
|
713
|
+
}
|
714
|
+
|
715
|
+
for (long jnode = 0; jnode < RARRAY_LEN(cache); jnode++) {
|
716
|
+
xmlNodePtr node;
|
717
|
+
VALUE element = rb_ary_entry(cache, jnode);
|
718
|
+
|
719
|
+
Noko_Node_Get_Struct(element, xmlNode, node);
|
720
|
+
if (xmlIsBlankNode(node)) {
|
721
|
+
return 1;
|
722
|
+
}
|
723
|
+
}
|
724
|
+
|
725
|
+
return 0;
|
726
|
+
}
|
643
727
|
|
644
728
|
void
|
645
729
|
noko_xml_document_pin_node(xmlNodePtr node)
|
data/ext/nokogiri/xml_dtd.c
CHANGED
@@ -139,7 +139,7 @@ validate(VALUE self, VALUE document)
|
|
139
139
|
VALUE error_list;
|
140
140
|
|
141
141
|
Noko_Node_Get_Struct(self, xmlDtd, dtd);
|
142
|
-
|
142
|
+
doc = noko_xml_document_unwrap(document);
|
143
143
|
error_list = rb_ary_new();
|
144
144
|
|
145
145
|
ctxt = xmlNewValidCtxt();
|
@@ -2,17 +2,22 @@
|
|
2
2
|
|
3
3
|
VALUE cNokogiriXmlElementContent;
|
4
4
|
|
5
|
+
static const rb_data_type_t element_content_data_type = {
|
6
|
+
.wrap_struct_name = "Nokogiri::XML::ElementContent",
|
7
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
8
|
+
};
|
9
|
+
|
5
10
|
/*
|
6
11
|
* call-seq:
|
7
|
-
*
|
12
|
+
* name → String
|
8
13
|
*
|
9
|
-
*
|
14
|
+
* [Returns] The content element's +name+
|
10
15
|
*/
|
11
16
|
static VALUE
|
12
17
|
get_name(VALUE self)
|
13
18
|
{
|
14
19
|
xmlElementContentPtr elem;
|
15
|
-
|
20
|
+
TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
|
16
21
|
|
17
22
|
if (!elem->name) { return Qnil; }
|
18
23
|
return NOKOGIRI_STR_NEW2(elem->name);
|
@@ -20,47 +25,40 @@ get_name(VALUE self)
|
|
20
25
|
|
21
26
|
/*
|
22
27
|
* call-seq:
|
23
|
-
*
|
28
|
+
* type → Integer
|
24
29
|
*
|
25
|
-
*
|
26
|
-
* or OR.
|
30
|
+
* [Returns] The content element's +type+. Possible values are +PCDATA+, +ELEMENT+, +SEQ+, or +OR+.
|
27
31
|
*/
|
28
32
|
static VALUE
|
29
33
|
get_type(VALUE self)
|
30
34
|
{
|
31
35
|
xmlElementContentPtr elem;
|
32
|
-
|
36
|
+
TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
|
33
37
|
|
34
38
|
return INT2NUM(elem->type);
|
35
39
|
}
|
36
40
|
|
37
41
|
/*
|
38
|
-
* call-seq:
|
39
|
-
* c1
|
40
|
-
*
|
41
42
|
* Get the first child.
|
42
43
|
*/
|
43
44
|
static VALUE
|
44
45
|
get_c1(VALUE self)
|
45
46
|
{
|
46
47
|
xmlElementContentPtr elem;
|
47
|
-
|
48
|
+
TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
|
48
49
|
|
49
50
|
if (!elem->c1) { return Qnil; }
|
50
51
|
return noko_xml_element_content_wrap(rb_iv_get(self, "@document"), elem->c1);
|
51
52
|
}
|
52
53
|
|
53
54
|
/*
|
54
|
-
*
|
55
|
-
* c2
|
56
|
-
*
|
57
|
-
* Get the first child.
|
55
|
+
* Get the second child.
|
58
56
|
*/
|
59
57
|
static VALUE
|
60
58
|
get_c2(VALUE self)
|
61
59
|
{
|
62
60
|
xmlElementContentPtr elem;
|
63
|
-
|
61
|
+
TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
|
64
62
|
|
65
63
|
if (!elem->c2) { return Qnil; }
|
66
64
|
return noko_xml_element_content_wrap(rb_iv_get(self, "@document"), elem->c2);
|
@@ -68,45 +66,50 @@ get_c2(VALUE self)
|
|
68
66
|
|
69
67
|
/*
|
70
68
|
* call-seq:
|
71
|
-
*
|
69
|
+
* occur → Integer
|
72
70
|
*
|
73
|
-
*
|
74
|
-
* or PLUS.
|
71
|
+
* [Returns] The content element's +occur+ flag. Possible values are +ONCE+, +OPT+, +MULT+ or +PLUS+.
|
75
72
|
*/
|
76
73
|
static VALUE
|
77
74
|
get_occur(VALUE self)
|
78
75
|
{
|
79
76
|
xmlElementContentPtr elem;
|
80
|
-
|
77
|
+
TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
|
81
78
|
|
82
79
|
return INT2NUM(elem->ocur);
|
83
80
|
}
|
84
81
|
|
85
82
|
/*
|
86
83
|
* call-seq:
|
87
|
-
*
|
84
|
+
* prefix → String
|
88
85
|
*
|
89
|
-
*
|
86
|
+
* [Returns] The content element's namespace +prefix+.
|
90
87
|
*/
|
91
88
|
static VALUE
|
92
89
|
get_prefix(VALUE self)
|
93
90
|
{
|
94
91
|
xmlElementContentPtr elem;
|
95
|
-
|
92
|
+
TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
|
96
93
|
|
97
94
|
if (!elem->prefix) { return Qnil; }
|
98
95
|
|
99
96
|
return NOKOGIRI_STR_NEW2(elem->prefix);
|
100
97
|
}
|
101
98
|
|
99
|
+
/*
|
100
|
+
* create a Nokogiri::XML::ElementContent object around an +element+.
|
101
|
+
*/
|
102
102
|
VALUE
|
103
|
-
noko_xml_element_content_wrap(VALUE
|
103
|
+
noko_xml_element_content_wrap(VALUE rb_document, xmlElementContentPtr c_element_content)
|
104
104
|
{
|
105
|
-
VALUE elem =
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
105
|
+
VALUE elem = TypedData_Wrap_Struct(
|
106
|
+
cNokogiriXmlElementContent,
|
107
|
+
&element_content_data_type,
|
108
|
+
c_element_content
|
109
|
+
);
|
110
|
+
|
111
|
+
/* keep a handle on the document for GC marking */
|
112
|
+
rb_iv_set(elem, "@document", rb_document);
|
110
113
|
|
111
114
|
return elem;
|
112
115
|
}
|
@@ -6,7 +6,7 @@ static ID id_document;
|
|
6
6
|
|
7
7
|
/*
|
8
8
|
* call-seq:
|
9
|
-
*
|
9
|
+
* element_type → Integer
|
10
10
|
*
|
11
11
|
* The element_type
|
12
12
|
*/
|
@@ -20,9 +20,9 @@ element_type(VALUE self)
|
|
20
20
|
|
21
21
|
/*
|
22
22
|
* call-seq:
|
23
|
-
*
|
23
|
+
* content → Nokogiri::XML::ElementContent
|
24
24
|
*
|
25
|
-
* The
|
25
|
+
* [Returns] The root of this element declaration's content tree.
|
26
26
|
*/
|
27
27
|
static VALUE
|
28
28
|
content(VALUE self)
|
@@ -40,9 +40,9 @@ content(VALUE self)
|
|
40
40
|
|
41
41
|
/*
|
42
42
|
* call-seq:
|
43
|
-
*
|
43
|
+
* prefix → String
|
44
44
|
*
|
45
|
-
* The namespace prefix for this
|
45
|
+
* [Returns] The namespace +prefix+ for this element declaration.
|
46
46
|
*/
|
47
47
|
static VALUE
|
48
48
|
prefix(VALUE self)
|
@@ -2,14 +2,22 @@
|
|
2
2
|
|
3
3
|
VALUE cNokogiriEncodingHandler;
|
4
4
|
|
5
|
-
|
6
5
|
static void
|
7
|
-
|
6
|
+
xml_encoding_handler_dealloc(void *data)
|
8
7
|
{
|
9
8
|
/* make sure iconv handlers are cleaned up and freed */
|
9
|
+
xmlCharEncodingHandlerPtr c_handler = data;
|
10
10
|
xmlCharEncCloseFunc(c_handler);
|
11
11
|
}
|
12
12
|
|
13
|
+
static const rb_data_type_t xml_encoding_handler_type = {
|
14
|
+
.wrap_struct_name = "Nokogiri::EncodingHandler",
|
15
|
+
.function = {
|
16
|
+
.dfree = xml_encoding_handler_dealloc,
|
17
|
+
},
|
18
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
19
|
+
};
|
20
|
+
|
13
21
|
|
14
22
|
/*
|
15
23
|
* call-seq: Nokogiri::EncodingHandler.[](name)
|
@@ -23,7 +31,7 @@ rb_xml_encoding_handler_s_get(VALUE klass, VALUE key)
|
|
23
31
|
|
24
32
|
handler = xmlFindCharEncodingHandler(StringValueCStr(key));
|
25
33
|
if (handler) {
|
26
|
-
return
|
34
|
+
return TypedData_Wrap_Struct(klass, &xml_encoding_handler_type, handler);
|
27
35
|
}
|
28
36
|
|
29
37
|
return Qnil;
|
@@ -82,7 +90,7 @@ rb_xml_encoding_handler_name(VALUE self)
|
|
82
90
|
{
|
83
91
|
xmlCharEncodingHandlerPtr handler;
|
84
92
|
|
85
|
-
|
93
|
+
TypedData_Get_Struct(self, xmlCharEncodingHandler, &xml_encoding_handler_type, handler);
|
86
94
|
|
87
95
|
return NOKOGIRI_STR_NEW2(handler->name);
|
88
96
|
}
|
@@ -56,21 +56,20 @@ _xml_namespace_update_references(void *ptr)
|
|
56
56
|
#endif
|
57
57
|
|
58
58
|
static const rb_data_type_t nokogiri_xml_namespace_type_with_dealloc = {
|
59
|
-
"Nokogiri
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
59
|
+
.wrap_struct_name = "Nokogiri::XML::Namespace#with_dealloc",
|
60
|
+
.function = {
|
61
|
+
.dfree = _xml_namespace_dealloc,
|
62
|
+
.dcompact = _xml_namespace_update_references,
|
63
|
+
},
|
64
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
65
65
|
};
|
66
66
|
|
67
67
|
static const rb_data_type_t nokogiri_xml_namespace_type_without_dealloc = {
|
68
|
-
"Nokogiri
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
RUBY_TYPED_FREE_IMMEDIATELY,
|
73
|
-
#endif
|
68
|
+
.wrap_struct_name = "Nokogiri::XML::Namespace#without_dealloc",
|
69
|
+
.function = {
|
70
|
+
.dcompact = _xml_namespace_update_references,
|
71
|
+
},
|
72
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
74
73
|
};
|
75
74
|
|
76
75
|
/*
|
data/ext/nokogiri/xml_node.c
CHANGED
@@ -43,12 +43,12 @@ _xml_node_update_references(void *ptr)
|
|
43
43
|
#endif
|
44
44
|
|
45
45
|
static const rb_data_type_t nokogiri_node_type = {
|
46
|
-
"Nokogiri
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
.wrap_struct_name = "Nokogiri::XML::Node",
|
47
|
+
.function = {
|
48
|
+
.dmark = _xml_node_mark,
|
49
|
+
.dcompact = _xml_node_update_references,
|
50
|
+
},
|
51
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
52
52
|
};
|
53
53
|
|
54
54
|
static void
|
@@ -350,7 +350,7 @@ ok:
|
|
350
350
|
|
351
351
|
xmlUnlinkNode(original_reparentee);
|
352
352
|
|
353
|
-
if (prf != xmlAddPrevSibling && prf != xmlAddNextSibling
|
353
|
+
if (prf != xmlAddPrevSibling && prf != xmlAddNextSibling && prf != xmlAddChild
|
354
354
|
&& reparentee->type == XML_TEXT_NODE && pivot->next && pivot->next->type == XML_TEXT_NODE) {
|
355
355
|
/*
|
356
356
|
* libxml merges text nodes in a right-to-left fashion, meaning that if
|
@@ -984,7 +984,7 @@ duplicate_node(int argc, VALUE *argv, VALUE self)
|
|
984
984
|
if (n_args < 2) {
|
985
985
|
new_parent_doc = node->doc;
|
986
986
|
} else {
|
987
|
-
|
987
|
+
new_parent_doc = noko_xml_document_unwrap(r_new_parent_doc);
|
988
988
|
}
|
989
989
|
|
990
990
|
dup = xmlDocCopyNode(node, new_parent_doc, level);
|