nokogiri 1.19.4-arm-linux-gnu → 1.19.6-arm-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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +29 -0
  3. data/ext/nokogiri/extconf.rb +1 -0
  4. data/ext/nokogiri/gumbo.c +83 -6
  5. data/ext/nokogiri/html4_document.c +10 -3
  6. data/ext/nokogiri/libxml2_polyfill.c +12 -0
  7. data/ext/nokogiri/nokogiri.c +84 -2
  8. data/ext/nokogiri/nokogiri.h +14 -1
  9. data/ext/nokogiri/xml_document.c +42 -16
  10. data/ext/nokogiri/xml_node.c +73 -38
  11. data/ext/nokogiri/xml_node_set.c +9 -9
  12. data/ext/nokogiri/xml_reader.c +198 -107
  13. data/ext/nokogiri/xml_sax_parser.c +3 -3
  14. data/ext/nokogiri/xml_sax_parser_context.c +38 -7
  15. data/ext/nokogiri/xml_sax_push_parser.c +12 -0
  16. data/ext/nokogiri/xml_xpath_context.c +124 -26
  17. data/ext/nokogiri/xslt_stylesheet.c +123 -27
  18. data/lib/nokogiri/3.2/nokogiri.so +0 -0
  19. data/lib/nokogiri/3.3/nokogiri.so +0 -0
  20. data/lib/nokogiri/3.4/nokogiri.so +0 -0
  21. data/lib/nokogiri/4.0/nokogiri.so +0 -0
  22. data/lib/nokogiri/css/parser.rb +35 -18
  23. data/lib/nokogiri/css/parser.y +35 -17
  24. data/lib/nokogiri/css/xpath_visitor.rb +71 -28
  25. data/lib/nokogiri/html5/document.rb +9 -0
  26. data/lib/nokogiri/html5/document_fragment.rb +16 -1
  27. data/lib/nokogiri/html5/node.rb +1 -1
  28. data/lib/nokogiri/html5.rb +16 -0
  29. data/lib/nokogiri/version/constant.rb +1 -1
  30. data/lib/nokogiri/xml/attr.rb +2 -0
  31. data/lib/nokogiri/xml/attribute_decl.rb +2 -1
  32. data/lib/nokogiri/xml/builder.rb +24 -32
  33. data/lib/nokogiri/xml/document.rb +1 -0
  34. data/lib/nokogiri/xml/dtd.rb +2 -1
  35. data/lib/nokogiri/xml/element_decl.rb +2 -1
  36. data/lib/nokogiri/xml/entity_decl.rb +2 -1
  37. data/lib/nokogiri/xml/node.rb +8 -6
  38. metadata +1 -1
@@ -115,14 +115,10 @@ relink_namespace(xmlNodePtr reparented)
115
115
  xmlNsPtr prev = NULL;
116
116
 
117
117
  while (curr) {
118
- xmlNsPtr ns = xmlSearchNsByHref(
119
- reparented->doc,
120
- reparented->parent,
121
- curr->href
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 {
@@ -1232,6 +1228,29 @@ namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
1232
1228
  return Qfalse;
1233
1229
  }
1234
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
+
1235
1254
  /*
1236
1255
  * call-seq:
1237
1256
  * []=(property, value)
@@ -1241,31 +1260,36 @@ namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
1241
1260
  static VALUE
1242
1261
  set(VALUE self, VALUE property, VALUE value)
1243
1262
  {
1244
- xmlNodePtr node, cur;
1245
- xmlAttrPtr prop;
1263
+ xmlNodePtr node;
1264
+ xmlNsPtr ns = NULL;
1265
+ const xmlChar *name, *local_name, *c_value;
1266
+ xmlChar *prefix;
1267
+ int prefix_len;
1246
1268
  Noko_Node_Get_Struct(self, xmlNode, node);
1247
1269
 
1248
- /* If a matching attribute node already exists, then xmlSetProp will destroy
1249
- * the existing node's children. However, if Nokogiri has a node object
1250
- * pointing to one of those children, we are left with a broken reference.
1251
- *
1252
- * We can avoid this by unlinking these nodes first.
1253
- */
1254
1270
  if (node->type != XML_ELEMENT_NODE) {
1255
1271
  return (Qnil);
1256
1272
  }
1257
- prop = xmlHasProp(node, (xmlChar *)StringValueCStr(property));
1258
- if (prop && prop->children) {
1259
- for (cur = prop->children; cur; cur = cur->next) {
1260
- if (cur->_private) {
1261
- noko_xml_document_pin_node(cur);
1262
- xmlUnlinkNode(cur);
1263
- }
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();
1264
1282
  }
1283
+ ns = xmlSearchNs(node->doc, node, prefix);
1284
+ xmlFree(prefix);
1285
+ }
1286
+ if (!ns) {
1287
+ local_name = name;
1265
1288
  }
1266
1289
 
1267
- xmlSetProp(node, (xmlChar *)StringValueCStr(property),
1268
- (xmlChar *)StringValueCStr(value));
1290
+ unlink_wrapped_attr_children(xmlHasNsProp(node, local_name, ns ? ns->href : NULL));
1291
+
1292
+ xmlSetNsProp(node, ns, local_name, c_value);
1269
1293
 
1270
1294
  return value;
1271
1295
  }
@@ -1338,6 +1362,11 @@ set_namespace(VALUE self, VALUE namespace)
1338
1362
 
1339
1363
  xmlSetNs(node, ns);
1340
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
+
1341
1370
  return self;
1342
1371
  }
1343
1372
 
@@ -1566,6 +1595,7 @@ set_lang(VALUE self_rb, VALUE lang_rb)
1566
1595
  Noko_Node_Get_Struct(self_rb, xmlNode, self);
1567
1596
  lang = (xmlChar *)StringValueCStr(lang_rb);
1568
1597
 
1598
+ unlink_wrapped_attr_children(xmlHasNsProp(self, BAD_CAST "lang", XML_XML_NAMESPACE));
1569
1599
  xmlNodeSetLang(self, lang);
1570
1600
 
1571
1601
  return Qnil ;
@@ -1744,7 +1774,7 @@ static inline void
1744
1774
  output_partial_string(VALUE out, char const *str, size_t length)
1745
1775
  {
1746
1776
  if (length) {
1747
- rb_enc_str_buf_cat(out, str, (long)length, rb_utf8_encoding());
1777
+ rb_enc_str_buf_cat(out, str, (rb_len_t)length, rb_utf8_encoding());
1748
1778
  }
1749
1779
  }
1750
1780
 
@@ -1834,9 +1864,9 @@ output_escaped_string(VALUE out, xmlChar const *start, bool attr)
1834
1864
  replaced_bytes = 2;
1835
1865
  } else if (attr && ch == '"') {
1836
1866
  replacement = """;
1837
- } else if (!attr && ch == '<') {
1867
+ } else if (ch == '<') {
1838
1868
  replacement = "&lt;";
1839
- } else if (!attr && ch == '>') {
1869
+ } else if (ch == '>') {
1840
1870
  replacement = "&gt;";
1841
1871
  } else {
1842
1872
  ++next;
@@ -1897,7 +1927,8 @@ static void
1897
1927
  output_node(
1898
1928
  VALUE out,
1899
1929
  xmlNodePtr node,
1900
- bool preserve_newline
1930
+ bool preserve_newline,
1931
+ bool scripting_enabled
1901
1932
  )
1902
1933
  {
1903
1934
  static char const *const VOID_ELEMENTS[] = {
@@ -1906,9 +1937,11 @@ output_node(
1906
1937
  };
1907
1938
 
1908
1939
  static char const *const UNESCAPED_TEXT_ELEMENTS[] = {
1909
- "style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext", "noscript",
1940
+ "style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext",
1910
1941
  };
1911
1942
 
1943
+ static char const *const NOSCRIPT_ELEMENT[] = { "noscript" };
1944
+
1912
1945
  switch (node->type) {
1913
1946
  case XML_ELEMENT_NODE:
1914
1947
  // Serialize the start tag.
@@ -1918,7 +1951,7 @@ output_node(
1918
1951
  // Add attributes.
1919
1952
  for (xmlAttrPtr attr = node->properties; attr; attr = attr->next) {
1920
1953
  output_char(out, ' ');
1921
- output_node(out, (xmlNodePtr)attr, preserve_newline);
1954
+ output_node(out, (xmlNodePtr)attr, preserve_newline, scripting_enabled);
1922
1955
  }
1923
1956
  output_char(out, '>');
1924
1957
 
@@ -1928,7 +1961,7 @@ output_node(
1928
1961
  output_char(out, '\n');
1929
1962
  }
1930
1963
  for (xmlNodePtr child = node->children; child; child = child->next) {
1931
- output_node(out, child, preserve_newline);
1964
+ output_node(out, child, preserve_newline, scripting_enabled);
1932
1965
  }
1933
1966
  output_string(out, "</");
1934
1967
  output_tagname(out, node);
@@ -1954,8 +1987,9 @@ output_node(
1954
1987
 
1955
1988
  case XML_TEXT_NODE:
1956
1989
  if (node->parent
1957
- && is_one_of(node->parent, UNESCAPED_TEXT_ELEMENTS,
1958
- sizeof UNESCAPED_TEXT_ELEMENTS / sizeof UNESCAPED_TEXT_ELEMENTS[0])) {
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)))) {
1959
1993
  output_string(out, (char const *)node->content);
1960
1994
  } else {
1961
1995
  output_escaped_string(out, node->content, false);
@@ -1991,7 +2025,7 @@ output_node(
1991
2025
  case XML_DOCUMENT_FRAG_NODE:
1992
2026
  case XML_HTML_DOCUMENT_NODE:
1993
2027
  for (xmlNodePtr child = node->children; child; child = child->next) {
1994
- output_node(out, child, preserve_newline);
2028
+ output_node(out, child, preserve_newline, scripting_enabled);
1995
2029
  }
1996
2030
  break;
1997
2031
 
@@ -2004,13 +2038,14 @@ output_node(
2004
2038
  static VALUE
2005
2039
  html_standard_serialize(
2006
2040
  VALUE self,
2007
- VALUE preserve_newline
2041
+ VALUE preserve_newline,
2042
+ VALUE scripting_enabled
2008
2043
  )
2009
2044
  {
2010
2045
  xmlNodePtr node;
2011
2046
  Noko_Node_Get_Struct(self, xmlNode, node);
2012
2047
  VALUE output = rb_str_buf_new(4096);
2013
- output_node(output, node, RTEST(preserve_newline));
2048
+ output_node(output, node, RTEST(preserve_newline), RTEST(scripting_enabled));
2014
2049
  return output;
2015
2050
  }
2016
2051
 
@@ -2512,7 +2547,7 @@ noko_init_xml_node(void)
2512
2547
  rb_define_private_method(cNokogiriXmlNode, "in_context", in_context, 2);
2513
2548
  rb_define_private_method(cNokogiriXmlNode, "native_write_to", native_write_to, 4);
2514
2549
  rb_define_private_method(cNokogiriXmlNode, "prepend_newline?", rb_prepend_newline, 0);
2515
- rb_define_private_method(cNokogiriXmlNode, "html_standard_serialize", html_standard_serialize, 1);
2550
+ rb_define_private_method(cNokogiriXmlNode, "html_standard_serialize", html_standard_serialize, 2);
2516
2551
  rb_define_private_method(cNokogiriXmlNode, "process_xincludes", noko_xml_node__process_xincludes, 1);
2517
2552
  rb_define_private_method(cNokogiriXmlNode, "replace_node", replace, 1);
2518
2553
  rb_define_private_method(cNokogiriXmlNode, "set", set, 2);
@@ -298,7 +298,7 @@ minus(VALUE rb_self, VALUE rb_other)
298
298
 
299
299
 
300
300
  static VALUE
301
- index_at(VALUE rb_self, long offset)
301
+ index_at(VALUE rb_self, rb_len_t offset)
302
302
  {
303
303
  xmlNodeSetPtr c_self;
304
304
 
@@ -314,9 +314,9 @@ index_at(VALUE rb_self, long offset)
314
314
  }
315
315
 
316
316
  static VALUE
317
- subseq(VALUE rb_self, long beg, long len)
317
+ subseq(VALUE rb_self, rb_len_t beg, rb_len_t len)
318
318
  {
319
- long j;
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
- long beg, len ;
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 = NUM2LONG(argv[0]);
365
- len = NUM2LONG(argv[1]);
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, FIX2LONG(arg));
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, (long)c_self->nodeNr, 0)) {
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, NUM2LONG(arg));
391
+ return index_at(rb_self, RB_NUM2LEN(arg));
392
392
  }
393
393
 
394
394