nokogiri 1.16.0 → 1.18.1
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 +14 -16
- data/LICENSE-DEPENDENCIES.md +6 -6
- data/README.md +8 -5
- data/dependencies.yml +9 -9
- data/ext/nokogiri/extconf.rb +188 -142
- data/ext/nokogiri/gumbo.c +69 -53
- data/ext/nokogiri/html4_document.c +10 -4
- data/ext/nokogiri/html4_element_description.c +18 -18
- data/ext/nokogiri/html4_sax_parser.c +40 -0
- data/ext/nokogiri/html4_sax_parser_context.c +48 -58
- data/ext/nokogiri/html4_sax_push_parser.c +25 -24
- data/ext/nokogiri/libxml2_polyfill.c +114 -0
- data/ext/nokogiri/nokogiri.c +9 -2
- data/ext/nokogiri/nokogiri.h +18 -33
- data/ext/nokogiri/xml_attr.c +1 -1
- data/ext/nokogiri/xml_cdata.c +2 -10
- data/ext/nokogiri/xml_comment.c +3 -8
- data/ext/nokogiri/xml_document.c +167 -156
- data/ext/nokogiri/xml_document_fragment.c +10 -25
- data/ext/nokogiri/xml_dtd.c +1 -1
- data/ext/nokogiri/xml_element_content.c +9 -9
- data/ext/nokogiri/xml_encoding_handler.c +4 -4
- data/ext/nokogiri/xml_namespace.c +6 -6
- data/ext/nokogiri/xml_node.c +141 -104
- data/ext/nokogiri/xml_node_set.c +46 -44
- data/ext/nokogiri/xml_reader.c +74 -57
- data/ext/nokogiri/xml_relax_ng.c +35 -56
- data/ext/nokogiri/xml_sax_parser.c +156 -88
- data/ext/nokogiri/xml_sax_parser_context.c +219 -131
- data/ext/nokogiri/xml_sax_push_parser.c +68 -49
- data/ext/nokogiri/xml_schema.c +50 -85
- data/ext/nokogiri/xml_syntax_error.c +19 -11
- data/ext/nokogiri/xml_text.c +2 -4
- data/ext/nokogiri/xml_xpath_context.c +103 -100
- data/ext/nokogiri/xslt_stylesheet.c +16 -11
- data/gumbo-parser/Makefile +3 -0
- data/gumbo-parser/src/ascii.c +2 -2
- data/gumbo-parser/src/error.c +76 -48
- data/gumbo-parser/src/error.h +5 -1
- data/gumbo-parser/src/nokogiri_gumbo.h +11 -2
- data/gumbo-parser/src/parser.c +66 -25
- data/gumbo-parser/src/tokenizer.c +6 -6
- data/lib/nokogiri/class_resolver.rb +1 -1
- data/lib/nokogiri/css/node.rb +6 -2
- data/lib/nokogiri/css/parser.rb +6 -4
- data/lib/nokogiri/css/parser.y +2 -2
- data/lib/nokogiri/css/parser_extras.rb +6 -66
- data/lib/nokogiri/css/selector_cache.rb +38 -0
- data/lib/nokogiri/css/tokenizer.rb +4 -4
- data/lib/nokogiri/css/tokenizer.rex +9 -8
- data/lib/nokogiri/css/xpath_visitor.rb +42 -6
- data/lib/nokogiri/css.rb +86 -20
- data/lib/nokogiri/decorators/slop.rb +3 -5
- data/lib/nokogiri/encoding_handler.rb +2 -2
- data/lib/nokogiri/html4/document.rb +44 -23
- data/lib/nokogiri/html4/document_fragment.rb +124 -12
- data/lib/nokogiri/html4/encoding_reader.rb +1 -1
- data/lib/nokogiri/html4/sax/parser.rb +23 -38
- data/lib/nokogiri/html4/sax/parser_context.rb +4 -9
- data/lib/nokogiri/html4.rb +9 -14
- data/lib/nokogiri/html5/builder.rb +40 -0
- data/lib/nokogiri/html5/document.rb +61 -30
- data/lib/nokogiri/html5/document_fragment.rb +130 -20
- data/lib/nokogiri/html5/node.rb +4 -4
- data/lib/nokogiri/html5.rb +114 -72
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/xml/builder.rb +8 -1
- data/lib/nokogiri/xml/document.rb +70 -26
- data/lib/nokogiri/xml/document_fragment.rb +84 -13
- data/lib/nokogiri/xml/node.rb +82 -11
- data/lib/nokogiri/xml/node_set.rb +9 -7
- data/lib/nokogiri/xml/parse_options.rb +1 -1
- data/lib/nokogiri/xml/pp/node.rb +6 -1
- data/lib/nokogiri/xml/reader.rb +51 -17
- data/lib/nokogiri/xml/relax_ng.rb +57 -20
- data/lib/nokogiri/xml/sax/document.rb +174 -83
- data/lib/nokogiri/xml/sax/parser.rb +115 -41
- data/lib/nokogiri/xml/sax/parser_context.rb +116 -8
- data/lib/nokogiri/xml/sax/push_parser.rb +3 -0
- data/lib/nokogiri/xml/sax.rb +48 -0
- data/lib/nokogiri/xml/schema.rb +112 -45
- data/lib/nokogiri/xml/searchable.rb +38 -42
- data/lib/nokogiri/xml/syntax_error.rb +22 -0
- data/lib/nokogiri/xml/xpath_context.rb +14 -3
- data/lib/nokogiri/xml.rb +13 -24
- data/lib/nokogiri/xslt/stylesheet.rb +29 -7
- data/lib/nokogiri/xslt.rb +3 -9
- data/lib/xsd/xmlparser/nokogiri.rb +3 -4
- data/patches/libxml2/0019-xpath-Use-separate-static-hash-table-for-standard-fu.patch +244 -0
- data/ports/archives/libxml2-2.13.5.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.42.tar.xz +0 -0
- metadata +13 -14
- data/ext/nokogiri/libxml2_backwards_compat.c +0 -121
- data/patches/libxml2/0003-libxml2.la-is-in-top_builddir.patch +0 -25
- data/ports/archives/libxml2-2.12.3.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.39.tar.xz +0 -0
data/ext/nokogiri/xml_document.c
CHANGED
@@ -17,6 +17,8 @@ dealloc_node_i2(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
|
|
17
17
|
break;
|
18
18
|
default:
|
19
19
|
if (node->parent == NULL) {
|
20
|
+
node->next = NULL;
|
21
|
+
node->prev = NULL;
|
20
22
|
xmlAddChild((xmlNodePtr)doc, node);
|
21
23
|
}
|
22
24
|
}
|
@@ -74,8 +76,10 @@ dealloc(void *data)
|
|
74
76
|
|
75
77
|
ruby_xfree(doc->_private);
|
76
78
|
|
79
|
+
#if defined(__GNUC__) && __GNUC__ >= 5
|
77
80
|
#pragma GCC diagnostic push
|
78
81
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" // xmlDeregisterNodeDefault is deprecated as of libxml2 2.11.0
|
82
|
+
#endif
|
79
83
|
/*
|
80
84
|
* libxml-ruby < 3.0.0 uses xmlDeregisterNodeDefault. If the user is using one of those older
|
81
85
|
* versions, the registered callback from libxml-ruby will access the _private pointers set by
|
@@ -90,7 +94,9 @@ dealloc(void *data)
|
|
90
94
|
if (xmlDeregisterNodeDefaultValue) {
|
91
95
|
remove_private((xmlNodePtr)doc);
|
92
96
|
}
|
97
|
+
#if defined(__GNUC__) && __GNUC__ >= 5
|
93
98
|
#pragma GCC diagnostic pop
|
99
|
+
#endif
|
94
100
|
|
95
101
|
xmlFreeDoc(doc);
|
96
102
|
}
|
@@ -103,7 +109,7 @@ memsize_node(const xmlNodePtr node)
|
|
103
109
|
xmlAttrPtr property;
|
104
110
|
size_t memsize = 0;
|
105
111
|
|
106
|
-
memsize += xmlStrlen(node->name);
|
112
|
+
memsize += (size_t)xmlStrlen(node->name);
|
107
113
|
|
108
114
|
if (node->type == XML_ELEMENT_NODE) {
|
109
115
|
for (property = node->properties; property; property = property->next) {
|
@@ -111,7 +117,7 @@ memsize_node(const xmlNodePtr node)
|
|
111
117
|
}
|
112
118
|
}
|
113
119
|
if (node->type == XML_TEXT_NODE) {
|
114
|
-
memsize += xmlStrlen(node->content);
|
120
|
+
memsize += (size_t)xmlStrlen(node->content);
|
115
121
|
}
|
116
122
|
for (child = node->children; child; child = child->next) {
|
117
123
|
memsize += sizeof(xmlNode) + memsize_node(child);
|
@@ -129,8 +135,8 @@ memsize(const void *data)
|
|
129
135
|
return memsize;
|
130
136
|
}
|
131
137
|
|
132
|
-
static const rb_data_type_t
|
133
|
-
.wrap_struct_name = "
|
138
|
+
static const rb_data_type_t xml_doc_type = {
|
139
|
+
.wrap_struct_name = "xmlDoc",
|
134
140
|
.function = {
|
135
141
|
.dmark = mark,
|
136
142
|
.dfree = dealloc,
|
@@ -139,6 +145,53 @@ static const rb_data_type_t noko_xml_document_data_type = {
|
|
139
145
|
// .flags = RUBY_TYPED_FREE_IMMEDIATELY, // TODO see https://github.com/sparklemotion/nokogiri/issues/2822
|
140
146
|
};
|
141
147
|
|
148
|
+
static VALUE
|
149
|
+
_xml_document_alloc(VALUE klass)
|
150
|
+
{
|
151
|
+
return TypedData_Wrap_Struct(klass, &xml_doc_type, NULL);
|
152
|
+
}
|
153
|
+
|
154
|
+
static void
|
155
|
+
_xml_document_data_ptr_set(VALUE rb_document, xmlDocPtr c_document)
|
156
|
+
{
|
157
|
+
nokogiriTuplePtr tuple;
|
158
|
+
|
159
|
+
assert(DATA_PTR(rb_document) == NULL);
|
160
|
+
assert(c_document->_private == NULL);
|
161
|
+
|
162
|
+
DATA_PTR(rb_document) = c_document;
|
163
|
+
|
164
|
+
tuple = (nokogiriTuplePtr)ruby_xmalloc(sizeof(nokogiriTuple));
|
165
|
+
tuple->doc = rb_document;
|
166
|
+
tuple->unlinkedNodes = st_init_numtable_with_size(128);
|
167
|
+
tuple->node_cache = rb_ary_new();
|
168
|
+
|
169
|
+
c_document->_private = tuple ;
|
170
|
+
|
171
|
+
rb_iv_set(rb_document, "@node_cache", tuple->node_cache);
|
172
|
+
|
173
|
+
return;
|
174
|
+
}
|
175
|
+
|
176
|
+
/* :nodoc: */
|
177
|
+
static VALUE
|
178
|
+
rb_xml_document_initialize_copy_with_args(VALUE rb_self, VALUE rb_other, VALUE rb_level)
|
179
|
+
{
|
180
|
+
xmlDocPtr c_other, c_self;
|
181
|
+
int c_level;
|
182
|
+
|
183
|
+
c_other = noko_xml_document_unwrap(rb_other);
|
184
|
+
c_level = (int)NUM2INT(rb_level);
|
185
|
+
|
186
|
+
c_self = xmlCopyDoc(c_other, c_level);
|
187
|
+
if (c_self == NULL) { return Qnil; }
|
188
|
+
|
189
|
+
c_self->type = c_other->type;
|
190
|
+
_xml_document_data_ptr_set(rb_self, c_self);
|
191
|
+
|
192
|
+
return rb_self ;
|
193
|
+
}
|
194
|
+
|
142
195
|
static void
|
143
196
|
recursively_remove_namespaces_from_node(xmlNodePtr node)
|
144
197
|
{
|
@@ -311,49 +364,46 @@ version(VALUE self)
|
|
311
364
|
* Create a new document from an IO object
|
312
365
|
*/
|
313
366
|
static VALUE
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
{
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
VALUE
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
367
|
+
noko_xml_document_s_read_io(VALUE rb_class,
|
368
|
+
VALUE rb_io,
|
369
|
+
VALUE rb_url,
|
370
|
+
VALUE rb_encoding,
|
371
|
+
VALUE rb_options)
|
372
|
+
{
|
373
|
+
/* TODO: deprecate this method, parse should be the preferred entry point. then we can make this
|
374
|
+
private. */
|
375
|
+
libxmlStructuredErrorHandlerState handler_state;
|
376
|
+
VALUE rb_errors = rb_ary_new();
|
377
|
+
|
378
|
+
noko__structured_error_func_save_and_set(&handler_state, (void *)rb_errors, noko__error_array_pusher);
|
379
|
+
|
380
|
+
const char *c_url = NIL_P(rb_url) ? NULL : StringValueCStr(rb_url);
|
381
|
+
const char *c_enc = NIL_P(rb_encoding) ? NULL : StringValueCStr(rb_encoding);
|
382
|
+
xmlDocPtr c_document = xmlReadIO(
|
383
|
+
(xmlInputReadCallback)noko_io_read,
|
384
|
+
(xmlInputCloseCallback)noko_io_close,
|
385
|
+
(void *)rb_io,
|
386
|
+
c_url,
|
387
|
+
c_enc,
|
388
|
+
(int)NUM2INT(rb_options)
|
389
|
+
);
|
390
|
+
|
391
|
+
noko__structured_error_func_restore(&handler_state);
|
392
|
+
|
393
|
+
if (c_document == NULL) {
|
394
|
+
xmlFreeDoc(c_document);
|
395
|
+
|
396
|
+
VALUE exception = rb_funcall(cNokogiriXmlSyntaxError, rb_intern("aggregate"), 1, rb_errors);
|
397
|
+
if (RB_TEST(exception)) {
|
398
|
+
rb_exc_raise(exception);
|
347
399
|
} else {
|
348
400
|
rb_raise(rb_eRuntimeError, "Could not parse document");
|
349
401
|
}
|
350
|
-
|
351
|
-
return Qnil;
|
352
402
|
}
|
353
403
|
|
354
|
-
|
355
|
-
rb_iv_set(
|
356
|
-
return
|
404
|
+
VALUE rb_document = noko_xml_document_wrap(rb_class, c_document);
|
405
|
+
rb_iv_set(rb_document, "@errors", rb_errors);
|
406
|
+
return rb_document;
|
357
407
|
}
|
358
408
|
|
359
409
|
/*
|
@@ -363,80 +413,44 @@ read_io(VALUE klass,
|
|
363
413
|
* Create a new document from a String
|
364
414
|
*/
|
365
415
|
static VALUE
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
{
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
VALUE error_list = rb_ary_new();
|
377
|
-
VALUE document;
|
378
|
-
xmlDocPtr doc;
|
379
|
-
|
380
|
-
xmlResetLastError();
|
381
|
-
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
382
|
-
doc = xmlReadMemory(c_buffer, len, c_url, c_enc, (int)NUM2INT(options));
|
383
|
-
xmlSetStructuredErrorFunc(NULL, NULL);
|
416
|
+
noko_xml_document_s_read_memory(VALUE rb_class,
|
417
|
+
VALUE rb_input,
|
418
|
+
VALUE rb_url,
|
419
|
+
VALUE rb_encoding,
|
420
|
+
VALUE rb_options)
|
421
|
+
{
|
422
|
+
/* TODO: deprecate this method, parse should be the preferred entry point. then we can make this
|
423
|
+
private. */
|
424
|
+
VALUE rb_errors = rb_ary_new();
|
425
|
+
xmlSetStructuredErrorFunc((void *)rb_errors, noko__error_array_pusher);
|
384
426
|
|
385
|
-
|
386
|
-
|
427
|
+
const char *c_buffer = StringValuePtr(rb_input);
|
428
|
+
const char *c_url = NIL_P(rb_url) ? NULL : StringValueCStr(rb_url);
|
429
|
+
const char *c_enc = NIL_P(rb_encoding) ? NULL : StringValueCStr(rb_encoding);
|
430
|
+
int c_buffer_len = (int)RSTRING_LEN(rb_input);
|
431
|
+
xmlDocPtr c_document = xmlReadMemory(c_buffer, c_buffer_len, c_url, c_enc, (int)NUM2INT(rb_options));
|
387
432
|
|
388
|
-
|
433
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
389
434
|
|
390
|
-
|
391
|
-
|
392
|
-
|
435
|
+
if (c_document == NULL) {
|
436
|
+
VALUE exception = rb_funcall(cNokogiriXmlSyntaxError, rb_intern("aggregate"), 1, rb_errors);
|
437
|
+
if (RB_TEST(exception)) {
|
438
|
+
rb_exc_raise(exception);
|
393
439
|
} else {
|
394
440
|
rb_raise(rb_eRuntimeError, "Could not parse document");
|
395
441
|
}
|
396
|
-
|
397
|
-
return Qnil;
|
398
442
|
}
|
399
443
|
|
400
|
-
document = noko_xml_document_wrap(
|
401
|
-
rb_iv_set(document, "@errors",
|
444
|
+
VALUE document = noko_xml_document_wrap(rb_class, c_document);
|
445
|
+
rb_iv_set(document, "@errors", rb_errors);
|
402
446
|
return document;
|
403
447
|
}
|
404
448
|
|
405
449
|
/*
|
406
450
|
* call-seq:
|
407
|
-
*
|
451
|
+
* new(version = "1.0")
|
408
452
|
*
|
409
|
-
*
|
410
|
-
* to a deep copy. 0 is a shallow copy, 1 is a deep copy.
|
411
|
-
*/
|
412
|
-
static VALUE
|
413
|
-
duplicate_document(int argc, VALUE *argv, VALUE self)
|
414
|
-
{
|
415
|
-
xmlDocPtr doc, dup;
|
416
|
-
VALUE copy;
|
417
|
-
VALUE level;
|
418
|
-
|
419
|
-
if (rb_scan_args(argc, argv, "01", &level) == 0) {
|
420
|
-
level = INT2NUM((long)1);
|
421
|
-
}
|
422
|
-
|
423
|
-
doc = noko_xml_document_unwrap(self);
|
424
|
-
|
425
|
-
dup = xmlCopyDoc(doc, (int)NUM2INT(level));
|
426
|
-
|
427
|
-
if (dup == NULL) { return Qnil; }
|
428
|
-
|
429
|
-
dup->type = doc->type;
|
430
|
-
copy = noko_xml_document_wrap(rb_obj_class(self), dup);
|
431
|
-
rb_iv_set(copy, "@errors", rb_iv_get(self, "@errors"));
|
432
|
-
return copy ;
|
433
|
-
}
|
434
|
-
|
435
|
-
/*
|
436
|
-
* call-seq:
|
437
|
-
* new(version = default)
|
438
|
-
*
|
439
|
-
* Create a new document with +version+ (defaults to "1.0")
|
453
|
+
* Create a new empty document declaring XML version +version+.
|
440
454
|
*/
|
441
455
|
static VALUE
|
442
456
|
new (int argc, VALUE *argv, VALUE klass)
|
@@ -499,55 +513,58 @@ remove_namespaces_bang(VALUE self)
|
|
499
513
|
return self;
|
500
514
|
}
|
501
515
|
|
502
|
-
/* call-seq:
|
516
|
+
/* call-seq:
|
517
|
+
* doc.create_entity(name, type, external_id, system_id, content)
|
503
518
|
*
|
504
519
|
* Create a new entity named +name+.
|
505
520
|
*
|
506
|
-
* +type+ is an integer representing the type of entity to be created, and it
|
507
|
-
*
|
508
|
-
*
|
521
|
+
* +type+ is an integer representing the type of entity to be created, and it defaults to
|
522
|
+
* +Nokogiri::XML::EntityDecl::INTERNAL_GENERAL+. See the constants on Nokogiri::XML::EntityDecl for
|
523
|
+
* more information.
|
509
524
|
*
|
510
525
|
* +external_id+, +system_id+, and +content+ set the External ID, System ID,
|
511
526
|
* and content respectively. All of these parameters are optional.
|
512
527
|
*/
|
513
528
|
static VALUE
|
514
|
-
|
515
|
-
{
|
516
|
-
VALUE
|
517
|
-
VALUE
|
518
|
-
VALUE
|
519
|
-
VALUE
|
520
|
-
VALUE
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
529
|
+
noko_xml_document__create_entity(int argc, VALUE *argv, VALUE rb_document)
|
530
|
+
{
|
531
|
+
VALUE rb_name;
|
532
|
+
VALUE rb_type;
|
533
|
+
VALUE rb_ext_id;
|
534
|
+
VALUE rb_sys_id;
|
535
|
+
VALUE rb_content;
|
536
|
+
|
537
|
+
rb_scan_args(argc, argv, "14",
|
538
|
+
&rb_name,
|
539
|
+
&rb_type, &rb_ext_id, &rb_sys_id, &rb_content);
|
540
|
+
|
541
|
+
xmlDocPtr c_document = noko_xml_document_unwrap(rb_document);
|
542
|
+
|
543
|
+
libxmlStructuredErrorHandlerState handler_state;
|
544
|
+
VALUE rb_errors = rb_ary_new();
|
545
|
+
noko__structured_error_func_save_and_set(&handler_state, (void *)rb_errors, noko__error_array_pusher);
|
546
|
+
|
547
|
+
xmlEntityPtr c_entity = xmlAddDocEntity(
|
548
|
+
c_document,
|
549
|
+
(xmlChar *)(NIL_P(rb_name) ? NULL : StringValueCStr(rb_name)),
|
550
|
+
(int)(NIL_P(rb_type) ? XML_INTERNAL_GENERAL_ENTITY : NUM2INT(rb_type)),
|
551
|
+
(xmlChar *)(NIL_P(rb_ext_id) ? NULL : StringValueCStr(rb_ext_id)),
|
552
|
+
(xmlChar *)(NIL_P(rb_sys_id) ? NULL : StringValueCStr(rb_sys_id)),
|
553
|
+
(xmlChar *)(NIL_P(rb_content) ? NULL : StringValueCStr(rb_content))
|
554
|
+
);
|
555
|
+
|
556
|
+
noko__structured_error_func_restore(&handler_state);
|
557
|
+
|
558
|
+
if (NULL == c_entity) {
|
559
|
+
VALUE exception = rb_funcall(cNokogiriXmlSyntaxError, rb_intern("aggregate"), 1, rb_errors);
|
560
|
+
if (RB_TEST(exception)) {
|
561
|
+
rb_exc_raise(exception);
|
543
562
|
} else {
|
544
563
|
rb_raise(rb_eRuntimeError, "Could not create entity");
|
545
564
|
}
|
546
|
-
|
547
|
-
return Qnil;
|
548
565
|
}
|
549
566
|
|
550
|
-
return noko_xml_node_wrap(cNokogiriXmlEntityDecl, (xmlNodePtr)
|
567
|
+
return noko_xml_node_wrap(cNokogiriXmlEntityDecl, (xmlNodePtr)c_entity);
|
551
568
|
}
|
552
569
|
|
553
570
|
static int
|
@@ -651,24 +668,16 @@ VALUE
|
|
651
668
|
noko_xml_document_wrap_with_init_args(VALUE klass, xmlDocPtr c_document, int argc, VALUE *argv)
|
652
669
|
{
|
653
670
|
VALUE rb_document;
|
654
|
-
nokogiriTuplePtr tuple;
|
655
671
|
|
656
672
|
if (!klass) {
|
657
673
|
klass = cNokogiriXmlDocument;
|
658
674
|
}
|
659
675
|
|
660
|
-
rb_document =
|
661
|
-
|
662
|
-
tuple = (nokogiriTuplePtr)ruby_xmalloc(sizeof(nokogiriTuple));
|
663
|
-
tuple->doc = rb_document;
|
664
|
-
tuple->unlinkedNodes = st_init_numtable_with_size(128);
|
665
|
-
tuple->node_cache = rb_ary_new();
|
666
|
-
|
667
|
-
c_document->_private = tuple ;
|
676
|
+
rb_document = _xml_document_alloc(klass);
|
677
|
+
_xml_document_data_ptr_set(rb_document, c_document);
|
668
678
|
|
669
679
|
rb_iv_set(rb_document, "@decorators", Qnil);
|
670
680
|
rb_iv_set(rb_document, "@errors", Qnil);
|
671
|
-
rb_iv_set(rb_document, "@node_cache", tuple->node_cache);
|
672
681
|
|
673
682
|
rb_obj_call_init(rb_document, argc, argv);
|
674
683
|
|
@@ -694,7 +703,7 @@ xmlDocPtr
|
|
694
703
|
noko_xml_document_unwrap(VALUE rb_document)
|
695
704
|
{
|
696
705
|
xmlDocPtr c_document;
|
697
|
-
TypedData_Get_Struct(rb_document, xmlDoc, &
|
706
|
+
TypedData_Get_Struct(rb_document, xmlDoc, &xml_doc_type, c_document);
|
698
707
|
return c_document;
|
699
708
|
}
|
700
709
|
|
@@ -751,13 +760,13 @@ void
|
|
751
760
|
noko_init_xml_document(void)
|
752
761
|
{
|
753
762
|
assert(cNokogiriXmlNode);
|
754
|
-
|
755
|
-
* Nokogiri::XML::Document wraps an xml document.
|
756
|
-
*/
|
763
|
+
|
757
764
|
cNokogiriXmlDocument = rb_define_class_under(mNokogiriXml, "Document", cNokogiriXmlNode);
|
758
765
|
|
759
|
-
|
760
|
-
|
766
|
+
rb_define_alloc_func(cNokogiriXmlDocument, _xml_document_alloc);
|
767
|
+
|
768
|
+
rb_define_singleton_method(cNokogiriXmlDocument, "read_memory", noko_xml_document_s_read_memory, 4);
|
769
|
+
rb_define_singleton_method(cNokogiriXmlDocument, "read_io", noko_xml_document_s_read_io, 4);
|
761
770
|
rb_define_singleton_method(cNokogiriXmlDocument, "new", new, -1);
|
762
771
|
|
763
772
|
rb_define_method(cNokogiriXmlDocument, "root", rb_xml_document_root, 0);
|
@@ -766,8 +775,10 @@ noko_init_xml_document(void)
|
|
766
775
|
rb_define_method(cNokogiriXmlDocument, "encoding=", set_encoding, 1);
|
767
776
|
rb_define_method(cNokogiriXmlDocument, "version", version, 0);
|
768
777
|
rb_define_method(cNokogiriXmlDocument, "canonicalize", rb_xml_document_canonicalize, -1);
|
769
|
-
rb_define_method(cNokogiriXmlDocument, "dup", duplicate_document, -1);
|
770
778
|
rb_define_method(cNokogiriXmlDocument, "url", url, 0);
|
771
|
-
rb_define_method(cNokogiriXmlDocument, "create_entity",
|
779
|
+
rb_define_method(cNokogiriXmlDocument, "create_entity", noko_xml_document__create_entity, -1);
|
772
780
|
rb_define_method(cNokogiriXmlDocument, "remove_namespaces!", remove_namespaces_bang, 0);
|
781
|
+
|
782
|
+
rb_define_protected_method(cNokogiriXmlDocument, "initialize_copy_with_args", rb_xml_document_initialize_copy_with_args,
|
783
|
+
2);
|
773
784
|
}
|
@@ -2,31 +2,18 @@
|
|
2
2
|
|
3
3
|
VALUE cNokogiriXmlDocumentFragment;
|
4
4
|
|
5
|
-
/*
|
6
|
-
* call-seq:
|
7
|
-
* new(document)
|
8
|
-
*
|
9
|
-
* Create a new DocumentFragment element on the +document+
|
10
|
-
*/
|
5
|
+
/* :nodoc: */
|
11
6
|
static VALUE
|
12
|
-
|
7
|
+
noko_xml_document_fragment_s_native_new(VALUE klass, VALUE rb_doc)
|
13
8
|
{
|
14
|
-
xmlDocPtr
|
15
|
-
xmlNodePtr
|
16
|
-
VALUE document;
|
17
|
-
VALUE rest;
|
9
|
+
xmlDocPtr c_doc;
|
10
|
+
xmlNodePtr c_node;
|
18
11
|
VALUE rb_node;
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
node = xmlNewDocFragment(xml_doc->doc);
|
25
|
-
|
26
|
-
noko_xml_document_pin_node(node);
|
27
|
-
|
28
|
-
rb_node = noko_xml_node_wrap(klass, node);
|
29
|
-
rb_obj_call_init(rb_node, argc, argv);
|
13
|
+
c_doc = noko_xml_document_unwrap(rb_doc);
|
14
|
+
c_node = xmlNewDocFragment(c_doc->doc);
|
15
|
+
noko_xml_document_pin_node(c_node);
|
16
|
+
rb_node = noko_xml_node_wrap(klass, c_node);
|
30
17
|
|
31
18
|
return rb_node;
|
32
19
|
}
|
@@ -35,10 +22,8 @@ void
|
|
35
22
|
noko_init_xml_document_fragment(void)
|
36
23
|
{
|
37
24
|
assert(cNokogiriXmlNode);
|
38
|
-
|
39
|
-
* DocumentFragment represents a DocumentFragment node in an xml document.
|
40
|
-
*/
|
25
|
+
|
41
26
|
cNokogiriXmlDocumentFragment = rb_define_class_under(mNokogiriXml, "DocumentFragment", cNokogiriXmlNode);
|
42
27
|
|
43
|
-
rb_define_singleton_method(cNokogiriXmlDocumentFragment, "
|
28
|
+
rb_define_singleton_method(cNokogiriXmlDocumentFragment, "native_new", noko_xml_document_fragment_s_native_new, 1);
|
44
29
|
}
|
data/ext/nokogiri/xml_dtd.c
CHANGED
@@ -144,7 +144,7 @@ validate(VALUE self, VALUE document)
|
|
144
144
|
|
145
145
|
ctxt = xmlNewValidCtxt();
|
146
146
|
|
147
|
-
xmlSetStructuredErrorFunc((void *)error_list,
|
147
|
+
xmlSetStructuredErrorFunc((void *)error_list, noko__error_array_pusher);
|
148
148
|
|
149
149
|
xmlValidateDtd(ctxt, doc, dtd);
|
150
150
|
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
VALUE cNokogiriXmlElementContent;
|
4
4
|
|
5
|
-
static const rb_data_type_t
|
6
|
-
.wrap_struct_name = "
|
5
|
+
static const rb_data_type_t xml_element_content_type = {
|
6
|
+
.wrap_struct_name = "xmlElementContent",
|
7
7
|
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
8
8
|
};
|
9
9
|
|
@@ -17,7 +17,7 @@ static VALUE
|
|
17
17
|
get_name(VALUE self)
|
18
18
|
{
|
19
19
|
xmlElementContentPtr elem;
|
20
|
-
TypedData_Get_Struct(self, xmlElementContent, &
|
20
|
+
TypedData_Get_Struct(self, xmlElementContent, &xml_element_content_type, elem);
|
21
21
|
|
22
22
|
if (!elem->name) { return Qnil; }
|
23
23
|
return NOKOGIRI_STR_NEW2(elem->name);
|
@@ -33,7 +33,7 @@ static VALUE
|
|
33
33
|
get_type(VALUE self)
|
34
34
|
{
|
35
35
|
xmlElementContentPtr elem;
|
36
|
-
TypedData_Get_Struct(self, xmlElementContent, &
|
36
|
+
TypedData_Get_Struct(self, xmlElementContent, &xml_element_content_type, elem);
|
37
37
|
|
38
38
|
return INT2NUM(elem->type);
|
39
39
|
}
|
@@ -45,7 +45,7 @@ static VALUE
|
|
45
45
|
get_c1(VALUE self)
|
46
46
|
{
|
47
47
|
xmlElementContentPtr elem;
|
48
|
-
TypedData_Get_Struct(self, xmlElementContent, &
|
48
|
+
TypedData_Get_Struct(self, xmlElementContent, &xml_element_content_type, elem);
|
49
49
|
|
50
50
|
if (!elem->c1) { return Qnil; }
|
51
51
|
return noko_xml_element_content_wrap(rb_iv_get(self, "@document"), elem->c1);
|
@@ -58,7 +58,7 @@ static VALUE
|
|
58
58
|
get_c2(VALUE self)
|
59
59
|
{
|
60
60
|
xmlElementContentPtr elem;
|
61
|
-
TypedData_Get_Struct(self, xmlElementContent, &
|
61
|
+
TypedData_Get_Struct(self, xmlElementContent, &xml_element_content_type, elem);
|
62
62
|
|
63
63
|
if (!elem->c2) { return Qnil; }
|
64
64
|
return noko_xml_element_content_wrap(rb_iv_get(self, "@document"), elem->c2);
|
@@ -74,7 +74,7 @@ static VALUE
|
|
74
74
|
get_occur(VALUE self)
|
75
75
|
{
|
76
76
|
xmlElementContentPtr elem;
|
77
|
-
TypedData_Get_Struct(self, xmlElementContent, &
|
77
|
+
TypedData_Get_Struct(self, xmlElementContent, &xml_element_content_type, elem);
|
78
78
|
|
79
79
|
return INT2NUM(elem->ocur);
|
80
80
|
}
|
@@ -89,7 +89,7 @@ static VALUE
|
|
89
89
|
get_prefix(VALUE self)
|
90
90
|
{
|
91
91
|
xmlElementContentPtr elem;
|
92
|
-
TypedData_Get_Struct(self, xmlElementContent, &
|
92
|
+
TypedData_Get_Struct(self, xmlElementContent, &xml_element_content_type, elem);
|
93
93
|
|
94
94
|
if (!elem->prefix) { return Qnil; }
|
95
95
|
|
@@ -104,7 +104,7 @@ noko_xml_element_content_wrap(VALUE rb_document, xmlElementContentPtr c_element_
|
|
104
104
|
{
|
105
105
|
VALUE elem = TypedData_Wrap_Struct(
|
106
106
|
cNokogiriXmlElementContent,
|
107
|
-
&
|
107
|
+
&xml_element_content_type,
|
108
108
|
c_element_content
|
109
109
|
);
|
110
110
|
|
@@ -10,8 +10,8 @@ xml_encoding_handler_dealloc(void *data)
|
|
10
10
|
xmlCharEncCloseFunc(c_handler);
|
11
11
|
}
|
12
12
|
|
13
|
-
static const rb_data_type_t
|
14
|
-
.wrap_struct_name = "
|
13
|
+
static const rb_data_type_t xml_char_encoding_handler_type = {
|
14
|
+
.wrap_struct_name = "xmlCharEncodingHandler",
|
15
15
|
.function = {
|
16
16
|
.dfree = xml_encoding_handler_dealloc,
|
17
17
|
},
|
@@ -31,7 +31,7 @@ rb_xml_encoding_handler_s_get(VALUE klass, VALUE key)
|
|
31
31
|
|
32
32
|
handler = xmlFindCharEncodingHandler(StringValueCStr(key));
|
33
33
|
if (handler) {
|
34
|
-
return TypedData_Wrap_Struct(klass, &
|
34
|
+
return TypedData_Wrap_Struct(klass, &xml_char_encoding_handler_type, handler);
|
35
35
|
}
|
36
36
|
|
37
37
|
return Qnil;
|
@@ -90,7 +90,7 @@ rb_xml_encoding_handler_name(VALUE self)
|
|
90
90
|
{
|
91
91
|
xmlCharEncodingHandlerPtr handler;
|
92
92
|
|
93
|
-
TypedData_Get_Struct(self, xmlCharEncodingHandler, &
|
93
|
+
TypedData_Get_Struct(self, xmlCharEncodingHandler, &xml_char_encoding_handler_type, handler);
|
94
94
|
|
95
95
|
return NOKOGIRI_STR_NEW2(handler->name);
|
96
96
|
}
|
@@ -51,8 +51,8 @@ _xml_namespace_update_references(void *ptr)
|
|
51
51
|
}
|
52
52
|
}
|
53
53
|
|
54
|
-
static const rb_data_type_t
|
55
|
-
.wrap_struct_name = "
|
54
|
+
static const rb_data_type_t xml_ns_type_with_free = {
|
55
|
+
.wrap_struct_name = "xmlNs (with free)",
|
56
56
|
.function = {
|
57
57
|
.dfree = _xml_namespace_dealloc,
|
58
58
|
.dcompact = _xml_namespace_update_references,
|
@@ -60,8 +60,8 @@ static const rb_data_type_t nokogiri_xml_namespace_type_with_dealloc = {
|
|
60
60
|
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
61
61
|
};
|
62
62
|
|
63
|
-
static const rb_data_type_t
|
64
|
-
.wrap_struct_name = "
|
63
|
+
static const rb_data_type_t xml_ns_type_without_free = {
|
64
|
+
.wrap_struct_name = "xmlNs (without free)",
|
65
65
|
.function = {
|
66
66
|
.dcompact = _xml_namespace_update_references,
|
67
67
|
},
|
@@ -145,7 +145,7 @@ noko_xml_namespace_wrap(xmlNsPtr c_namespace, xmlDocPtr c_document)
|
|
145
145
|
|
146
146
|
if (c_document) {
|
147
147
|
rb_namespace = TypedData_Wrap_Struct(cNokogiriXmlNamespace,
|
148
|
-
&
|
148
|
+
&xml_ns_type_without_free,
|
149
149
|
c_namespace);
|
150
150
|
|
151
151
|
if (DOC_RUBY_OBJECT_TEST(c_document)) {
|
@@ -154,7 +154,7 @@ noko_xml_namespace_wrap(xmlNsPtr c_namespace, xmlDocPtr c_document)
|
|
154
154
|
}
|
155
155
|
} else {
|
156
156
|
rb_namespace = TypedData_Wrap_Struct(cNokogiriXmlNamespace,
|
157
|
-
&
|
157
|
+
&xml_ns_type_with_free,
|
158
158
|
c_namespace);
|
159
159
|
}
|
160
160
|
|