nokogiri 1.19.3-aarch64-linux-gnu → 1.19.5-aarch64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE-DEPENDENCIES.md +29 -0
- data/ext/nokogiri/extconf.rb +1 -0
- data/ext/nokogiri/gumbo.c +83 -6
- data/ext/nokogiri/html4_document.c +10 -3
- data/ext/nokogiri/libxml2_polyfill.c +12 -0
- data/ext/nokogiri/nokogiri.c +90 -5
- data/ext/nokogiri/nokogiri.h +25 -3
- data/ext/nokogiri/xml_attr.c +28 -23
- data/ext/nokogiri/xml_document.c +64 -30
- data/ext/nokogiri/xml_node.c +151 -52
- data/ext/nokogiri/xml_node_set.c +10 -10
- data/ext/nokogiri/xml_reader.c +198 -107
- data/ext/nokogiri/xml_sax_parser.c +3 -3
- data/ext/nokogiri/xml_sax_parser_context.c +38 -7
- data/ext/nokogiri/xml_sax_push_parser.c +12 -0
- data/ext/nokogiri/xml_xpath_context.c +135 -27
- data/ext/nokogiri/xslt_stylesheet.c +123 -27
- data/lib/nokogiri/3.2/nokogiri.so +0 -0
- data/lib/nokogiri/3.3/nokogiri.so +0 -0
- data/lib/nokogiri/3.4/nokogiri.so +0 -0
- data/lib/nokogiri/4.0/nokogiri.so +0 -0
- data/lib/nokogiri/css/parser.rb +35 -18
- data/lib/nokogiri/css/parser.y +35 -17
- data/lib/nokogiri/css/xpath_visitor.rb +71 -28
- data/lib/nokogiri/html5/document.rb +9 -0
- data/lib/nokogiri/html5/document_fragment.rb +16 -1
- data/lib/nokogiri/html5/node.rb +1 -1
- data/lib/nokogiri/html5.rb +16 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +10 -0
- data/lib/nokogiri/xml/attr.rb +2 -0
- data/lib/nokogiri/xml/attribute_decl.rb +2 -1
- data/lib/nokogiri/xml/builder.rb +24 -32
- data/lib/nokogiri/xml/document.rb +4 -2
- data/lib/nokogiri/xml/dtd.rb +2 -1
- data/lib/nokogiri/xml/element_decl.rb +2 -1
- data/lib/nokogiri/xml/entity_decl.rb +2 -1
- data/lib/nokogiri/xml/node.rb +65 -12
- metadata +1 -1
data/ext/nokogiri/xml_document.c
CHANGED
|
@@ -255,12 +255,6 @@ rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
|
|
|
255
255
|
|
|
256
256
|
c_document = noko_xml_document_unwrap(self);
|
|
257
257
|
|
|
258
|
-
c_current_root = xmlDocGetRootElement(c_document);
|
|
259
|
-
if (c_current_root) {
|
|
260
|
-
xmlUnlinkNode(c_current_root);
|
|
261
|
-
noko_xml_document_pin_node(c_current_root);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
258
|
if (!NIL_P(rb_new_root)) {
|
|
265
259
|
if (!rb_obj_is_kind_of(rb_new_root, cNokogiriXmlNode)) {
|
|
266
260
|
rb_raise(rb_eArgError,
|
|
@@ -270,13 +264,23 @@ rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
|
|
|
270
264
|
|
|
271
265
|
Noko_Node_Get_Struct(rb_new_root, xmlNode, c_new_root);
|
|
272
266
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
267
|
+
if (c_new_root->type != XML_ELEMENT_NODE) {
|
|
268
|
+
rb_raise(rb_eTypeError, "root must be a Nokogiri::XML::Element");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
c_current_root = xmlDocGetRootElement(c_document);
|
|
273
|
+
if (c_current_root) {
|
|
274
|
+
xmlUnlinkNode(c_current_root);
|
|
275
|
+
noko_xml_document_pin_node(c_current_root);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/* If the new root's document is not the same as the current document,
|
|
279
|
+
* then we need to dup the node in to this document. */
|
|
280
|
+
if (c_new_root && c_new_root->doc != c_document) {
|
|
281
|
+
c_new_root = xmlDocCopyNode(c_new_root, c_document, 1);
|
|
282
|
+
if (!c_new_root) {
|
|
283
|
+
rb_raise(rb_eRuntimeError, "Could not reparent node (xmlDocCopyNode)");
|
|
280
284
|
}
|
|
281
285
|
}
|
|
282
286
|
|
|
@@ -317,12 +321,13 @@ static VALUE
|
|
|
317
321
|
set_encoding(VALUE self, VALUE encoding)
|
|
318
322
|
{
|
|
319
323
|
xmlDocPtr doc = noko_xml_document_unwrap(self);
|
|
324
|
+
xmlChar *new_encoding = xmlStrdup((xmlChar *)StringValueCStr(encoding));
|
|
320
325
|
|
|
321
326
|
if (doc->encoding) {
|
|
322
327
|
xmlFree(DISCARD_CONST_QUAL_XMLCHAR(doc->encoding));
|
|
323
328
|
}
|
|
324
329
|
|
|
325
|
-
doc->encoding =
|
|
330
|
+
doc->encoding = new_encoding;
|
|
326
331
|
|
|
327
332
|
return encoding;
|
|
328
333
|
}
|
|
@@ -379,17 +384,24 @@ noko_xml_document_s_read_io(VALUE rb_class,
|
|
|
379
384
|
|
|
380
385
|
const char *c_url = NIL_P(rb_url) ? NULL : StringValueCStr(rb_url);
|
|
381
386
|
const char *c_enc = NIL_P(rb_encoding) ? NULL : StringValueCStr(rb_encoding);
|
|
387
|
+
noko_io_read_reset_exception();
|
|
382
388
|
xmlDocPtr c_document = xmlReadIO(
|
|
383
|
-
(xmlInputReadCallback)
|
|
389
|
+
(xmlInputReadCallback)noko_io_read_protected,
|
|
384
390
|
(xmlInputCloseCallback)noko_io_close,
|
|
385
391
|
(void *)rb_io,
|
|
386
392
|
c_url,
|
|
387
393
|
c_enc,
|
|
388
394
|
(int)NUM2INT(rb_options)
|
|
389
395
|
);
|
|
396
|
+
VALUE rb_io_read_exception = noko_io_read_take_exception();
|
|
390
397
|
|
|
391
398
|
noko__structured_error_func_restore(&handler_state);
|
|
392
399
|
|
|
400
|
+
if (!NIL_P(rb_io_read_exception)) {
|
|
401
|
+
xmlFreeDoc(c_document);
|
|
402
|
+
noko_io_read_raise_exception(rb_io_read_exception);
|
|
403
|
+
}
|
|
404
|
+
|
|
393
405
|
if (c_document == NULL) {
|
|
394
406
|
xmlFreeDoc(c_document);
|
|
395
407
|
|
|
@@ -459,7 +471,7 @@ new (int argc, VALUE *argv, VALUE klass)
|
|
|
459
471
|
VALUE version, rest, rb_doc ;
|
|
460
472
|
|
|
461
473
|
rb_scan_args(argc, argv, "0*", &rest);
|
|
462
|
-
version = rb_ary_entry(rest, (
|
|
474
|
+
version = rb_ary_entry(rest, (rb_len_t)0);
|
|
463
475
|
if (NIL_P(version)) { version = rb_str_new2("1.0"); }
|
|
464
476
|
|
|
465
477
|
doc = xmlNewDoc((xmlChar *)StringValueCStr(version));
|
|
@@ -604,7 +616,8 @@ rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
|
|
|
604
616
|
VALUE rb_namespaces;
|
|
605
617
|
VALUE rb_comments_p;
|
|
606
618
|
int c_mode = 0;
|
|
607
|
-
xmlChar **c_namespaces;
|
|
619
|
+
xmlChar **c_namespaces = NULL;
|
|
620
|
+
VALUE rb_namespaces_buffer = 0;
|
|
608
621
|
|
|
609
622
|
xmlDocPtr c_doc;
|
|
610
623
|
xmlOutputBufferPtr c_obuf;
|
|
@@ -624,6 +637,35 @@ rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
|
|
|
624
637
|
if (c_mode == XML_C14N_1_0 || c_mode == XML_C14N_1_1) {
|
|
625
638
|
rb_raise(rb_eRuntimeError, "This canonicalizer does not support this operation");
|
|
626
639
|
}
|
|
640
|
+
|
|
641
|
+
// Copy every prefix into one temporary buffer before libxml2 sees it. Converting first means a
|
|
642
|
+
// raise from #to_str or a null byte leaks nothing. Copying means GC compaction, which moves the
|
|
643
|
+
// bytes of embedded strings, cannot move a prefix while libxml2 reads it. No allocation may
|
|
644
|
+
// happen between reading a prefix's pointer and copying its bytes.
|
|
645
|
+
rb_len_t ns_len = RARRAY_LEN(rb_namespaces);
|
|
646
|
+
VALUE rb_prefixes = rb_ary_new_capa(ns_len);
|
|
647
|
+
for (rb_len_t j = 0; j < ns_len; j++) {
|
|
648
|
+
VALUE entry = rb_ary_entry(rb_namespaces, j);
|
|
649
|
+
StringValueCStr(entry);
|
|
650
|
+
rb_ary_push(rb_prefixes, entry);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
size_t size = ((size_t)ns_len + 1) * sizeof(xmlChar *);
|
|
654
|
+
for (rb_len_t j = 0; j < ns_len; j++) {
|
|
655
|
+
size += (size_t)RSTRING_LEN(RARRAY_AREF(rb_prefixes, j)) + 1;
|
|
656
|
+
}
|
|
657
|
+
c_namespaces = ALLOCV(rb_namespaces_buffer, size);
|
|
658
|
+
|
|
659
|
+
xmlChar *c_prefix = (xmlChar *)(c_namespaces + ns_len + 1);
|
|
660
|
+
for (rb_len_t j = 0; j < ns_len; j++) {
|
|
661
|
+
VALUE prefix = RARRAY_AREF(rb_prefixes, j);
|
|
662
|
+
size_t prefix_len = (size_t)RSTRING_LEN(prefix);
|
|
663
|
+
memcpy(c_prefix, RSTRING_PTR(prefix), prefix_len);
|
|
664
|
+
c_prefix[prefix_len] = '\0';
|
|
665
|
+
c_namespaces[j] = c_prefix;
|
|
666
|
+
c_prefix += prefix_len + 1;
|
|
667
|
+
}
|
|
668
|
+
c_namespaces[ns_len] = NULL;
|
|
627
669
|
}
|
|
628
670
|
|
|
629
671
|
c_doc = noko_xml_document_unwrap(self);
|
|
@@ -641,24 +683,13 @@ rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
|
|
|
641
683
|
rb_callback = (void *)rb_block_proc();
|
|
642
684
|
}
|
|
643
685
|
|
|
644
|
-
if (NIL_P(rb_namespaces)) {
|
|
645
|
-
c_namespaces = NULL;
|
|
646
|
-
} else {
|
|
647
|
-
long ns_len = RARRAY_LEN(rb_namespaces);
|
|
648
|
-
c_namespaces = ruby_xcalloc((size_t)ns_len + 1, sizeof(xmlChar *));
|
|
649
|
-
for (int j = 0 ; j < ns_len ; j++) {
|
|
650
|
-
VALUE entry = rb_ary_entry(rb_namespaces, j);
|
|
651
|
-
c_namespaces[j] = (xmlChar *)StringValueCStr(entry);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
|
|
655
686
|
int ret = xmlC14NExecute(c_doc, c_callback_wrapper, rb_callback,
|
|
656
687
|
c_mode,
|
|
657
688
|
c_namespaces,
|
|
658
689
|
(int)RTEST(rb_comments_p),
|
|
659
690
|
c_obuf);
|
|
660
691
|
|
|
661
|
-
|
|
692
|
+
ALLOCV_END(rb_namespaces_buffer);
|
|
662
693
|
xmlOutputBufferClose(c_obuf);
|
|
663
694
|
|
|
664
695
|
if (ret < 0) {
|
|
@@ -708,6 +739,9 @@ noko_xml_document_unwrap(VALUE rb_document)
|
|
|
708
739
|
{
|
|
709
740
|
xmlDocPtr c_document;
|
|
710
741
|
TypedData_Get_Struct(rb_document, xmlDoc, &xml_doc_type, c_document);
|
|
742
|
+
if (c_document == NULL) {
|
|
743
|
+
rb_raise(rb_eRuntimeError, "Uninitialized %" PRIsVALUE " struct (null data pointer)", rb_obj_class(rb_document));
|
|
744
|
+
}
|
|
711
745
|
return c_document;
|
|
712
746
|
}
|
|
713
747
|
|
|
@@ -725,7 +759,7 @@ noko_xml_document_has_wrapped_blank_nodes_p(xmlDocPtr c_document)
|
|
|
725
759
|
return 0;
|
|
726
760
|
}
|
|
727
761
|
|
|
728
|
-
for (
|
|
762
|
+
for (rb_len_t jnode = 0; jnode < RARRAY_LEN(cache); jnode++) {
|
|
729
763
|
xmlNodePtr node;
|
|
730
764
|
VALUE element = rb_ary_entry(cache, jnode);
|
|
731
765
|
|
data/ext/nokogiri/xml_node.c
CHANGED
|
@@ -115,14 +115,10 @@ relink_namespace(xmlNodePtr reparented)
|
|
|
115
115
|
xmlNsPtr prev = NULL;
|
|
116
116
|
|
|
117
117
|
while (curr) {
|
|
118
|
-
xmlNsPtr ns =
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
);
|
|
123
|
-
/* If we find the namespace is already declared, remove it from this
|
|
124
|
-
* definition list. */
|
|
125
|
-
if (ns && ns != curr && xmlStrEqual(ns->prefix, curr->prefix)) {
|
|
118
|
+
xmlNsPtr ns = xmlSearchNs(reparented->doc, reparented->parent, curr->prefix);
|
|
119
|
+
/* If the parent already binds this prefix to the same href, remove it
|
|
120
|
+
* from this definition list. */
|
|
121
|
+
if (ns && ns != curr && xmlStrEqual(ns->href, curr->href)) {
|
|
126
122
|
if (prev) {
|
|
127
123
|
prev->next = curr->next;
|
|
128
124
|
} else {
|
|
@@ -971,6 +967,10 @@ rb_xml_node_initialize_copy_with_args(VALUE rb_self, VALUE rb_other, VALUE rb_le
|
|
|
971
967
|
xmlDocPtr c_new_parent_doc;
|
|
972
968
|
VALUE rb_node_cache;
|
|
973
969
|
|
|
970
|
+
if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNode)) {
|
|
971
|
+
rb_raise(rb_eTypeError, "argument must be a kind of Nokogiri::XML::Node");
|
|
972
|
+
}
|
|
973
|
+
|
|
974
974
|
Noko_Node_Get_Struct(rb_other, xmlNode, c_other);
|
|
975
975
|
c_level = (int)NUM2INT(rb_level);
|
|
976
976
|
c_new_parent_doc = noko_xml_document_unwrap(rb_new_parent_doc);
|
|
@@ -1228,6 +1228,29 @@ namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
|
|
|
1228
1228
|
return Qfalse;
|
|
1229
1229
|
}
|
|
1230
1230
|
|
|
1231
|
+
/* If a matching attribute node already exists, then xmlSetNsProp will destroy
|
|
1232
|
+
* the existing node's children. However, if Nokogiri has a node object
|
|
1233
|
+
* pointing to one of those children, we are left with a broken reference.
|
|
1234
|
+
*
|
|
1235
|
+
* We can avoid this by unlinking these nodes first.
|
|
1236
|
+
*/
|
|
1237
|
+
static void
|
|
1238
|
+
unlink_wrapped_attr_children(xmlAttrPtr attr)
|
|
1239
|
+
{
|
|
1240
|
+
xmlNodePtr cur, next;
|
|
1241
|
+
|
|
1242
|
+
if (!attr || attr->type != XML_ATTRIBUTE_NODE) {
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
for (cur = attr->children; cur; cur = next) {
|
|
1246
|
+
next = cur->next;
|
|
1247
|
+
if (cur->_private) {
|
|
1248
|
+
noko_xml_document_pin_node(cur);
|
|
1249
|
+
xmlUnlinkNode(cur);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1231
1254
|
/*
|
|
1232
1255
|
* call-seq:
|
|
1233
1256
|
* []=(property, value)
|
|
@@ -1237,31 +1260,36 @@ namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
|
|
|
1237
1260
|
static VALUE
|
|
1238
1261
|
set(VALUE self, VALUE property, VALUE value)
|
|
1239
1262
|
{
|
|
1240
|
-
xmlNodePtr node
|
|
1241
|
-
|
|
1263
|
+
xmlNodePtr node;
|
|
1264
|
+
xmlNsPtr ns = NULL;
|
|
1265
|
+
const xmlChar *name, *local_name, *c_value;
|
|
1266
|
+
xmlChar *prefix;
|
|
1267
|
+
int prefix_len;
|
|
1242
1268
|
Noko_Node_Get_Struct(self, xmlNode, node);
|
|
1243
1269
|
|
|
1244
|
-
/* If a matching attribute node already exists, then xmlSetProp will destroy
|
|
1245
|
-
* the existing node's children. However, if Nokogiri has a node object
|
|
1246
|
-
* pointing to one of those children, we are left with a broken reference.
|
|
1247
|
-
*
|
|
1248
|
-
* We can avoid this by unlinking these nodes first.
|
|
1249
|
-
*/
|
|
1250
1270
|
if (node->type != XML_ELEMENT_NODE) {
|
|
1251
1271
|
return (Qnil);
|
|
1252
1272
|
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1273
|
+
name = (const xmlChar *)StringValueCStr(property);
|
|
1274
|
+
c_value = (const xmlChar *)StringValueCStr(value);
|
|
1275
|
+
|
|
1276
|
+
/* Resolve a QName the way xmlSetProp does, so that we find the same attribute it would replace. */
|
|
1277
|
+
local_name = xmlSplitQName3(name, &prefix_len);
|
|
1278
|
+
if (local_name) {
|
|
1279
|
+
prefix = xmlStrndup(name, prefix_len);
|
|
1280
|
+
if (!prefix) {
|
|
1281
|
+
rb_memerror();
|
|
1260
1282
|
}
|
|
1283
|
+
ns = xmlSearchNs(node->doc, node, prefix);
|
|
1284
|
+
xmlFree(prefix);
|
|
1285
|
+
}
|
|
1286
|
+
if (!ns) {
|
|
1287
|
+
local_name = name;
|
|
1261
1288
|
}
|
|
1262
1289
|
|
|
1263
|
-
|
|
1264
|
-
|
|
1290
|
+
unlink_wrapped_attr_children(xmlHasNsProp(node, local_name, ns ? ns->href : NULL));
|
|
1291
|
+
|
|
1292
|
+
xmlSetNsProp(node, ns, local_name, c_value);
|
|
1265
1293
|
|
|
1266
1294
|
return value;
|
|
1267
1295
|
}
|
|
@@ -1334,6 +1362,11 @@ set_namespace(VALUE self, VALUE namespace)
|
|
|
1334
1362
|
|
|
1335
1363
|
xmlSetNs(node, ns);
|
|
1336
1364
|
|
|
1365
|
+
if (ns && node->type == XML_ELEMENT_NODE && !xmlSearchNs(node->doc, node, ns->prefix)) {
|
|
1366
|
+
xmlNsPtr definition = xmlNewNs(node, ns->href, ns->prefix);
|
|
1367
|
+
if (definition) { xmlSetNs(node, definition); }
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1337
1370
|
return self;
|
|
1338
1371
|
}
|
|
1339
1372
|
|
|
@@ -1562,6 +1595,7 @@ set_lang(VALUE self_rb, VALUE lang_rb)
|
|
|
1562
1595
|
Noko_Node_Get_Struct(self_rb, xmlNode, self);
|
|
1563
1596
|
lang = (xmlChar *)StringValueCStr(lang_rb);
|
|
1564
1597
|
|
|
1598
|
+
unlink_wrapped_attr_children(xmlHasNsProp(self, BAD_CAST "lang", XML_XML_NAMESPACE));
|
|
1565
1599
|
xmlNodeSetLang(self, lang);
|
|
1566
1600
|
|
|
1567
1601
|
return Qnil ;
|
|
@@ -1740,7 +1774,7 @@ static inline void
|
|
|
1740
1774
|
output_partial_string(VALUE out, char const *str, size_t length)
|
|
1741
1775
|
{
|
|
1742
1776
|
if (length) {
|
|
1743
|
-
rb_enc_str_buf_cat(out, str, (
|
|
1777
|
+
rb_enc_str_buf_cat(out, str, (rb_len_t)length, rb_utf8_encoding());
|
|
1744
1778
|
}
|
|
1745
1779
|
}
|
|
1746
1780
|
|
|
@@ -1830,9 +1864,9 @@ output_escaped_string(VALUE out, xmlChar const *start, bool attr)
|
|
|
1830
1864
|
replaced_bytes = 2;
|
|
1831
1865
|
} else if (attr && ch == '"') {
|
|
1832
1866
|
replacement = """;
|
|
1833
|
-
} else if (
|
|
1867
|
+
} else if (ch == '<') {
|
|
1834
1868
|
replacement = "<";
|
|
1835
|
-
} else if (
|
|
1869
|
+
} else if (ch == '>') {
|
|
1836
1870
|
replacement = ">";
|
|
1837
1871
|
} else {
|
|
1838
1872
|
++next;
|
|
@@ -1893,7 +1927,8 @@ static void
|
|
|
1893
1927
|
output_node(
|
|
1894
1928
|
VALUE out,
|
|
1895
1929
|
xmlNodePtr node,
|
|
1896
|
-
bool preserve_newline
|
|
1930
|
+
bool preserve_newline,
|
|
1931
|
+
bool scripting_enabled
|
|
1897
1932
|
)
|
|
1898
1933
|
{
|
|
1899
1934
|
static char const *const VOID_ELEMENTS[] = {
|
|
@@ -1902,9 +1937,11 @@ output_node(
|
|
|
1902
1937
|
};
|
|
1903
1938
|
|
|
1904
1939
|
static char const *const UNESCAPED_TEXT_ELEMENTS[] = {
|
|
1905
|
-
"style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext",
|
|
1940
|
+
"style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext",
|
|
1906
1941
|
};
|
|
1907
1942
|
|
|
1943
|
+
static char const *const NOSCRIPT_ELEMENT[] = { "noscript" };
|
|
1944
|
+
|
|
1908
1945
|
switch (node->type) {
|
|
1909
1946
|
case XML_ELEMENT_NODE:
|
|
1910
1947
|
// Serialize the start tag.
|
|
@@ -1914,7 +1951,7 @@ output_node(
|
|
|
1914
1951
|
// Add attributes.
|
|
1915
1952
|
for (xmlAttrPtr attr = node->properties; attr; attr = attr->next) {
|
|
1916
1953
|
output_char(out, ' ');
|
|
1917
|
-
output_node(out, (xmlNodePtr)attr, preserve_newline);
|
|
1954
|
+
output_node(out, (xmlNodePtr)attr, preserve_newline, scripting_enabled);
|
|
1918
1955
|
}
|
|
1919
1956
|
output_char(out, '>');
|
|
1920
1957
|
|
|
@@ -1924,7 +1961,7 @@ output_node(
|
|
|
1924
1961
|
output_char(out, '\n');
|
|
1925
1962
|
}
|
|
1926
1963
|
for (xmlNodePtr child = node->children; child; child = child->next) {
|
|
1927
|
-
output_node(out, child, preserve_newline);
|
|
1964
|
+
output_node(out, child, preserve_newline, scripting_enabled);
|
|
1928
1965
|
}
|
|
1929
1966
|
output_string(out, "</");
|
|
1930
1967
|
output_tagname(out, node);
|
|
@@ -1950,8 +1987,9 @@ output_node(
|
|
|
1950
1987
|
|
|
1951
1988
|
case XML_TEXT_NODE:
|
|
1952
1989
|
if (node->parent
|
|
1953
|
-
&& is_one_of(node->parent, UNESCAPED_TEXT_ELEMENTS,
|
|
1954
|
-
|
|
1990
|
+
&& (is_one_of(node->parent, UNESCAPED_TEXT_ELEMENTS,
|
|
1991
|
+
sizeof UNESCAPED_TEXT_ELEMENTS / sizeof UNESCAPED_TEXT_ELEMENTS[0])
|
|
1992
|
+
|| (scripting_enabled && is_one_of(node->parent, NOSCRIPT_ELEMENT, 1)))) {
|
|
1955
1993
|
output_string(out, (char const *)node->content);
|
|
1956
1994
|
} else {
|
|
1957
1995
|
output_escaped_string(out, node->content, false);
|
|
@@ -1987,7 +2025,7 @@ output_node(
|
|
|
1987
2025
|
case XML_DOCUMENT_FRAG_NODE:
|
|
1988
2026
|
case XML_HTML_DOCUMENT_NODE:
|
|
1989
2027
|
for (xmlNodePtr child = node->children; child; child = child->next) {
|
|
1990
|
-
output_node(out, child, preserve_newline);
|
|
2028
|
+
output_node(out, child, preserve_newline, scripting_enabled);
|
|
1991
2029
|
}
|
|
1992
2030
|
break;
|
|
1993
2031
|
|
|
@@ -2000,13 +2038,14 @@ output_node(
|
|
|
2000
2038
|
static VALUE
|
|
2001
2039
|
html_standard_serialize(
|
|
2002
2040
|
VALUE self,
|
|
2003
|
-
VALUE preserve_newline
|
|
2041
|
+
VALUE preserve_newline,
|
|
2042
|
+
VALUE scripting_enabled
|
|
2004
2043
|
)
|
|
2005
2044
|
{
|
|
2006
2045
|
xmlNodePtr node;
|
|
2007
2046
|
Noko_Node_Get_Struct(self, xmlNode, node);
|
|
2008
2047
|
VALUE output = rb_str_buf_new(4096);
|
|
2009
|
-
output_node(output, node, RTEST(preserve_newline));
|
|
2048
|
+
output_node(output, node, RTEST(preserve_newline), RTEST(scripting_enabled));
|
|
2010
2049
|
return output;
|
|
2011
2050
|
}
|
|
2012
2051
|
|
|
@@ -2150,25 +2189,20 @@ compare(VALUE self, VALUE _other)
|
|
|
2150
2189
|
|
|
2151
2190
|
|
|
2152
2191
|
/*
|
|
2153
|
-
*
|
|
2154
|
-
*
|
|
2155
|
-
*
|
|
2156
|
-
* Loads and substitutes all xinclude elements below the node. The
|
|
2157
|
-
* parser context will be initialized with +flags+.
|
|
2192
|
+
* Run XInclude substitution over the tree rooted at +c_node+, with the parser context initialized
|
|
2193
|
+
* from +c_flags+. Collects libxml2's structured errors and raises Nokogiri::XML::SyntaxError (or
|
|
2194
|
+
* RuntimeError) on failure.
|
|
2158
2195
|
*/
|
|
2159
|
-
static
|
|
2160
|
-
|
|
2196
|
+
static void
|
|
2197
|
+
_noko_xml_node_process_xinclude_subtree(xmlNodePtr c_node, int c_flags)
|
|
2161
2198
|
{
|
|
2162
2199
|
int status ;
|
|
2163
|
-
xmlNodePtr c_node;
|
|
2164
2200
|
VALUE rb_errors = rb_ary_new();
|
|
2165
2201
|
libxmlStructuredErrorHandlerState handler_state;
|
|
2166
2202
|
|
|
2167
|
-
Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
|
|
2168
|
-
|
|
2169
2203
|
noko__structured_error_func_save_and_set(&handler_state, (void *)rb_errors, noko__error_array_pusher);
|
|
2170
2204
|
|
|
2171
|
-
status = xmlXIncludeProcessTreeFlags(c_node,
|
|
2205
|
+
status = xmlXIncludeProcessTreeFlags(c_node, c_flags);
|
|
2172
2206
|
|
|
2173
2207
|
noko__structured_error_func_restore(&handler_state);
|
|
2174
2208
|
|
|
@@ -2181,11 +2215,77 @@ noko_xml_node__process_xincludes(VALUE rb_node, VALUE rb_flags)
|
|
|
2181
2215
|
rb_raise(rb_eRuntimeError, "Could not perform xinclude substitution");
|
|
2182
2216
|
}
|
|
2183
2217
|
}
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
|
|
2221
|
+
/*
|
|
2222
|
+
* Whether +c_node+ is an <xi:include> element in either the 2001 or 2003 XInclude namespace.
|
|
2223
|
+
*/
|
|
2224
|
+
static int
|
|
2225
|
+
_noko_xml_node_xinclude_element_p(xmlNodePtr c_node)
|
|
2226
|
+
{
|
|
2227
|
+
return c_node->type == XML_ELEMENT_NODE
|
|
2228
|
+
&& xmlStrEqual(c_node->name, XINCLUDE_NODE)
|
|
2229
|
+
&& c_node->ns != NULL
|
|
2230
|
+
&& (xmlStrEqual(c_node->ns->href, XINCLUDE_NS) || xmlStrEqual(c_node->ns->href, XINCLUDE_OLD_NS));
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
|
|
2234
|
+
/*
|
|
2235
|
+
* call-seq:
|
|
2236
|
+
* process_xincludes(flags)
|
|
2237
|
+
*
|
|
2238
|
+
* Loads and substitutes all xinclude elements below the node. The
|
|
2239
|
+
* parser context will be initialized with +flags+.
|
|
2240
|
+
*/
|
|
2241
|
+
static VALUE
|
|
2242
|
+
noko_xml_node__process_xincludes(VALUE rb_node, VALUE rb_flags)
|
|
2243
|
+
{
|
|
2244
|
+
xmlNodePtr c_node;
|
|
2245
|
+
|
|
2246
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
|
|
2247
|
+
|
|
2248
|
+
if (c_node->parent == NULL && _noko_xml_node_xinclude_element_p(c_node)) {
|
|
2249
|
+
rb_raise(rb_eRuntimeError, "cannot process XInclude on an unlinked <xi:include> node");
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
_noko_xml_node_process_xinclude_subtree(c_node, (int)NUM2INT(rb_flags));
|
|
2184
2253
|
|
|
2185
2254
|
return rb_node;
|
|
2186
2255
|
}
|
|
2187
2256
|
|
|
2188
2257
|
|
|
2258
|
+
/*
|
|
2259
|
+
* Process this single <xi:include> node, substituting an unwrapped copy of it in its place so
|
|
2260
|
+
* that libxml2 frees the copy. This node is unlinked and pinned to the document, so any Ruby
|
|
2261
|
+
* wrapper for it (or for its descendants or namespaces) keeps pointing at valid memory. The
|
|
2262
|
+
* parser context is initialized with +flags+.
|
|
2263
|
+
*/
|
|
2264
|
+
static VALUE
|
|
2265
|
+
noko_xml_node__safe_process_xinclude(VALUE rb_node, VALUE rb_flags)
|
|
2266
|
+
{
|
|
2267
|
+
xmlNodePtr c_node, c_copy;
|
|
2268
|
+
|
|
2269
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
|
|
2270
|
+
|
|
2271
|
+
if (c_node->parent == NULL) {
|
|
2272
|
+
rb_raise(rb_eRuntimeError, "cannot process XInclude on an unlinked <xi:include> node");
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
c_copy = xmlDocCopyNode(c_node, c_node->doc, 1);
|
|
2276
|
+
if (c_copy == NULL) {
|
|
2277
|
+
rb_raise(rb_eRuntimeError, "Could not copy node for xinclude substitution");
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
xmlReplaceNode(c_node, c_copy);
|
|
2281
|
+
noko_xml_document_pin_node(c_node);
|
|
2282
|
+
|
|
2283
|
+
_noko_xml_node_process_xinclude_subtree(c_copy, (int)NUM2INT(rb_flags));
|
|
2284
|
+
|
|
2285
|
+
return Qnil;
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
|
|
2189
2289
|
/* TODO: DOCUMENT ME */
|
|
2190
2290
|
static VALUE
|
|
2191
2291
|
in_context(VALUE self, VALUE _str, VALUE _options)
|
|
@@ -2286,9 +2386,7 @@ in_context(VALUE self, VALUE _str, VALUE _options)
|
|
|
2286
2386
|
VALUE
|
|
2287
2387
|
rb_xml_node_data_ptr_eh(VALUE self)
|
|
2288
2388
|
{
|
|
2289
|
-
|
|
2290
|
-
Noko_Node_Get_Struct(self, xmlNode, c_node);
|
|
2291
|
-
return c_node ? Qtrue : Qfalse;
|
|
2389
|
+
return DATA_PTR(self) ? Qtrue : Qfalse;
|
|
2292
2390
|
}
|
|
2293
2391
|
|
|
2294
2392
|
VALUE
|
|
@@ -2438,6 +2536,7 @@ noko_init_xml_node(void)
|
|
|
2438
2536
|
rb_define_method(cNokogiriXmlNode, "unlink", unlink_node, 0);
|
|
2439
2537
|
|
|
2440
2538
|
rb_define_protected_method(cNokogiriXmlNode, "initialize_copy_with_args", rb_xml_node_initialize_copy_with_args, 3);
|
|
2539
|
+
rb_define_protected_method(cNokogiriXmlNode, "safe_process_xinclude", noko_xml_node__safe_process_xinclude, 1);
|
|
2441
2540
|
|
|
2442
2541
|
rb_define_private_method(cNokogiriXmlNode, "add_child_node", add_child, 1);
|
|
2443
2542
|
rb_define_private_method(cNokogiriXmlNode, "add_next_sibling_node", add_next_sibling, 1);
|
|
@@ -2448,7 +2547,7 @@ noko_init_xml_node(void)
|
|
|
2448
2547
|
rb_define_private_method(cNokogiriXmlNode, "in_context", in_context, 2);
|
|
2449
2548
|
rb_define_private_method(cNokogiriXmlNode, "native_write_to", native_write_to, 4);
|
|
2450
2549
|
rb_define_private_method(cNokogiriXmlNode, "prepend_newline?", rb_prepend_newline, 0);
|
|
2451
|
-
rb_define_private_method(cNokogiriXmlNode, "html_standard_serialize", html_standard_serialize,
|
|
2550
|
+
rb_define_private_method(cNokogiriXmlNode, "html_standard_serialize", html_standard_serialize, 2);
|
|
2452
2551
|
rb_define_private_method(cNokogiriXmlNode, "process_xincludes", noko_xml_node__process_xincludes, 1);
|
|
2453
2552
|
rb_define_private_method(cNokogiriXmlNode, "replace_node", replace, 1);
|
|
2454
2553
|
rb_define_private_method(cNokogiriXmlNode, "set", set, 2);
|
data/ext/nokogiri/xml_node_set.c
CHANGED
|
@@ -298,13 +298,13 @@ minus(VALUE rb_self, VALUE rb_other)
|
|
|
298
298
|
|
|
299
299
|
|
|
300
300
|
static VALUE
|
|
301
|
-
index_at(VALUE rb_self,
|
|
301
|
+
index_at(VALUE rb_self, rb_len_t offset)
|
|
302
302
|
{
|
|
303
303
|
xmlNodeSetPtr c_self;
|
|
304
304
|
|
|
305
305
|
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
|
306
306
|
|
|
307
|
-
if (offset >= c_self->nodeNr ||
|
|
307
|
+
if (offset >= c_self->nodeNr || offset < -c_self->nodeNr) {
|
|
308
308
|
return Qnil;
|
|
309
309
|
}
|
|
310
310
|
|
|
@@ -314,9 +314,9 @@ index_at(VALUE rb_self, long offset)
|
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
static VALUE
|
|
317
|
-
subseq(VALUE rb_self,
|
|
317
|
+
subseq(VALUE rb_self, rb_len_t beg, rb_len_t len)
|
|
318
318
|
{
|
|
319
|
-
|
|
319
|
+
rb_len_t j;
|
|
320
320
|
xmlNodeSetPtr c_self;
|
|
321
321
|
xmlNodeSetPtr new_set ;
|
|
322
322
|
|
|
@@ -355,14 +355,14 @@ static VALUE
|
|
|
355
355
|
slice(int argc, VALUE *argv, VALUE rb_self)
|
|
356
356
|
{
|
|
357
357
|
VALUE arg ;
|
|
358
|
-
|
|
358
|
+
rb_len_t beg, len ;
|
|
359
359
|
xmlNodeSetPtr c_self;
|
|
360
360
|
|
|
361
361
|
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
|
362
362
|
|
|
363
363
|
if (argc == 2) {
|
|
364
|
-
beg =
|
|
365
|
-
len =
|
|
364
|
+
beg = RB_NUM2LEN(argv[0]);
|
|
365
|
+
len = RB_NUM2LEN(argv[1]);
|
|
366
366
|
if (beg < 0) {
|
|
367
367
|
beg += c_self->nodeNr ;
|
|
368
368
|
}
|
|
@@ -375,11 +375,11 @@ slice(int argc, VALUE *argv, VALUE rb_self)
|
|
|
375
375
|
arg = argv[0];
|
|
376
376
|
|
|
377
377
|
if (FIXNUM_P(arg)) {
|
|
378
|
-
return index_at(rb_self,
|
|
378
|
+
return index_at(rb_self, RB_FIX2LEN(arg));
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
/* if arg is Range */
|
|
382
|
-
switch (rb_range_beg_len(arg, &beg, &len, (
|
|
382
|
+
switch (rb_range_beg_len(arg, &beg, &len, (rb_len_t)c_self->nodeNr, 0)) {
|
|
383
383
|
case Qfalse:
|
|
384
384
|
break;
|
|
385
385
|
case Qnil:
|
|
@@ -388,7 +388,7 @@ slice(int argc, VALUE *argv, VALUE rb_self)
|
|
|
388
388
|
return subseq(rb_self, beg, len);
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
return index_at(rb_self,
|
|
391
|
+
return index_at(rb_self, RB_NUM2LEN(arg));
|
|
392
392
|
}
|
|
393
393
|
|
|
394
394
|
|