nokogiri 1.13.6 → 1.14.2

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.

Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +39 -0
  3. data/LICENSE-DEPENDENCIES.md +830 -509
  4. data/LICENSE.md +1 -1
  5. data/README.md +18 -11
  6. data/dependencies.yml +33 -15
  7. data/ext/nokogiri/extconf.rb +100 -24
  8. data/ext/nokogiri/gumbo.c +21 -11
  9. data/ext/nokogiri/html4_document.c +2 -2
  10. data/ext/nokogiri/html4_element_description.c +1 -1
  11. data/ext/nokogiri/html4_entity_lookup.c +2 -2
  12. data/ext/nokogiri/html4_sax_parser_context.c +1 -6
  13. data/ext/nokogiri/html4_sax_push_parser.c +1 -1
  14. data/ext/nokogiri/nokogiri.c +38 -51
  15. data/ext/nokogiri/nokogiri.h +26 -14
  16. data/ext/nokogiri/test_global_handlers.c +1 -1
  17. data/ext/nokogiri/xml_attr.c +3 -3
  18. data/ext/nokogiri/xml_attribute_decl.c +5 -5
  19. data/ext/nokogiri/xml_cdata.c +3 -3
  20. data/ext/nokogiri/xml_comment.c +1 -1
  21. data/ext/nokogiri/xml_document.c +23 -14
  22. data/ext/nokogiri/xml_document_fragment.c +1 -1
  23. data/ext/nokogiri/xml_dtd.c +9 -9
  24. data/ext/nokogiri/xml_element_content.c +3 -3
  25. data/ext/nokogiri/xml_element_decl.c +5 -5
  26. data/ext/nokogiri/xml_encoding_handler.c +3 -3
  27. data/ext/nokogiri/xml_entity_decl.c +6 -6
  28. data/ext/nokogiri/xml_entity_reference.c +1 -1
  29. data/ext/nokogiri/xml_namespace.c +80 -14
  30. data/ext/nokogiri/xml_node.c +363 -82
  31. data/ext/nokogiri/xml_node_set.c +4 -6
  32. data/ext/nokogiri/xml_processing_instruction.c +1 -1
  33. data/ext/nokogiri/xml_reader.c +97 -22
  34. data/ext/nokogiri/xml_relax_ng.c +1 -3
  35. data/ext/nokogiri/xml_sax_parser.c +23 -17
  36. data/ext/nokogiri/xml_sax_parser_context.c +1 -6
  37. data/ext/nokogiri/xml_sax_push_parser.c +1 -3
  38. data/ext/nokogiri/xml_schema.c +4 -6
  39. data/ext/nokogiri/xml_syntax_error.c +1 -1
  40. data/ext/nokogiri/xml_text.c +2 -2
  41. data/ext/nokogiri/xml_xpath_context.c +91 -84
  42. data/ext/nokogiri/xslt_stylesheet.c +15 -14
  43. data/gumbo-parser/Makefile +10 -0
  44. data/gumbo-parser/src/attribute.h +1 -1
  45. data/gumbo-parser/src/error.c +2 -2
  46. data/gumbo-parser/src/error.h +1 -1
  47. data/gumbo-parser/src/foreign_attrs.c +2 -2
  48. data/gumbo-parser/src/{gumbo.h → nokogiri_gumbo.h} +1 -0
  49. data/gumbo-parser/src/parser.c +8 -5
  50. data/gumbo-parser/src/replacement.h +1 -1
  51. data/gumbo-parser/src/string_buffer.h +1 -1
  52. data/gumbo-parser/src/string_piece.c +1 -1
  53. data/gumbo-parser/src/svg_attrs.c +2 -2
  54. data/gumbo-parser/src/svg_tags.c +2 -2
  55. data/gumbo-parser/src/tag.c +2 -1
  56. data/gumbo-parser/src/tag_lookup.c +7 -7
  57. data/gumbo-parser/src/tag_lookup.gperf +1 -0
  58. data/gumbo-parser/src/tag_lookup.h +1 -1
  59. data/gumbo-parser/src/token_buffer.h +1 -1
  60. data/gumbo-parser/src/tokenizer.c +1 -1
  61. data/gumbo-parser/src/tokenizer.h +1 -1
  62. data/gumbo-parser/src/utf8.c +1 -1
  63. data/gumbo-parser/src/utf8.h +1 -1
  64. data/gumbo-parser/src/util.c +1 -3
  65. data/gumbo-parser/src/util.h +4 -0
  66. data/gumbo-parser/src/vector.h +1 -1
  67. data/lib/nokogiri/css/node.rb +2 -2
  68. data/lib/nokogiri/css/xpath_visitor.rb +5 -3
  69. data/lib/nokogiri/css.rb +6 -0
  70. data/lib/nokogiri/decorators/slop.rb +1 -1
  71. data/lib/nokogiri/encoding_handler.rb +57 -0
  72. data/lib/nokogiri/extension.rb +3 -2
  73. data/lib/nokogiri/html4/document.rb +2 -121
  74. data/lib/nokogiri/html4/element_description_defaults.rb +6 -12
  75. data/lib/nokogiri/html4/encoding_reader.rb +121 -0
  76. data/lib/nokogiri/html4.rb +1 -0
  77. data/lib/nokogiri/html5/document.rb +113 -36
  78. data/lib/nokogiri/html5/document_fragment.rb +9 -2
  79. data/lib/nokogiri/html5/node.rb +3 -5
  80. data/lib/nokogiri/html5.rb +127 -216
  81. data/lib/nokogiri/jruby/dependencies.rb +1 -19
  82. data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
  83. data/lib/nokogiri/version/constant.rb +1 -1
  84. data/lib/nokogiri/version/info.rb +11 -10
  85. data/lib/nokogiri/xml/attr.rb +49 -0
  86. data/lib/nokogiri/xml/builder.rb +1 -1
  87. data/lib/nokogiri/xml/document.rb +103 -55
  88. data/lib/nokogiri/xml/document_fragment.rb +49 -6
  89. data/lib/nokogiri/xml/namespace.rb +42 -0
  90. data/lib/nokogiri/xml/node/save_options.rb +6 -4
  91. data/lib/nokogiri/xml/node.rb +190 -35
  92. data/lib/nokogiri/xml/node_set.rb +88 -9
  93. data/lib/nokogiri/xml/parse_options.rb +129 -50
  94. data/lib/nokogiri/xml/pp/node.rb +6 -4
  95. data/lib/nokogiri/xml/processing_instruction.rb +2 -1
  96. data/lib/nokogiri/xml/reader.rb +6 -8
  97. data/lib/nokogiri/xml/sax/parser.rb +2 -3
  98. data/lib/nokogiri/xslt.rb +1 -1
  99. data/lib/nokogiri.rb +3 -11
  100. data/lib/xsd/xmlparser/nokogiri.rb +3 -1
  101. data/ports/archives/libxml2-2.10.3.tar.xz +0 -0
  102. data/ports/archives/libxslt-1.1.37.tar.xz +0 -0
  103. metadata +11 -242
  104. data/patches/libxml2/0004-use-glibc-strlen.patch +0 -53
  105. data/patches/libxml2/0005-avoid-isnan-isinf.patch +0 -81
  106. data/patches/libxml2/0006-update-automake-files-for-arm64.patch +0 -3040
  107. data/patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch +0 -61
  108. data/ports/archives/libxml2-2.9.14.tar.xz +0 -0
  109. data/ports/archives/libxslt-1.1.35.tar.xz +0 -0
@@ -6,15 +6,15 @@ VALUE cNokogiriXmlXpathContext;
6
6
  * these constants have matching declarations in
7
7
  * ext/java/nokogiri/internals/NokogiriNamespaceContext.java
8
8
  */
9
+ static const xmlChar *NOKOGIRI_PREFIX = (const xmlChar *)"nokogiri";
10
+ static const xmlChar *NOKOGIRI_URI = (const xmlChar *)"http://www.nokogiri.org/default_ns/ruby/extensions_functions";
9
11
  static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-builtin";
10
12
  static const xmlChar *NOKOGIRI_BUILTIN_URI = (const xmlChar *)"https://www.nokogiri.org/default_ns/ruby/builtins";
11
13
 
12
14
  static void
13
- deallocate(xmlXPathContextPtr ctx)
15
+ xml_xpath_context_deallocate(xmlXPathContextPtr ctx)
14
16
  {
15
- NOKOGIRI_DEBUG_START(ctx);
16
17
  xmlXPathFreeContext(ctx);
17
- NOKOGIRI_DEBUG_END(ctx);
18
18
  }
19
19
 
20
20
  /* find a CSS class in an HTML element's `class` attribute */
@@ -113,7 +113,7 @@ xpath_builtin_local_name_is(xmlXPathParserContextPtr ctxt, int nargs)
113
113
  * Register the namespace with +prefix+ and +uri+.
114
114
  */
115
115
  static VALUE
116
- register_ns(VALUE self, VALUE prefix, VALUE uri)
116
+ rb_xml_xpath_context_register_ns(VALUE self, VALUE prefix, VALUE uri)
117
117
  {
118
118
  xmlXPathContextPtr ctx;
119
119
  Data_Get_Struct(self, xmlXPathContext, ctx);
@@ -132,7 +132,7 @@ register_ns(VALUE self, VALUE prefix, VALUE uri)
132
132
  * Register the variable +name+ with +value+.
133
133
  */
134
134
  static VALUE
135
- register_variable(VALUE self, VALUE name, VALUE value)
135
+ rb_xml_xpath_context_register_variable(VALUE self, VALUE name, VALUE value)
136
136
  {
137
137
  xmlXPathContextPtr ctx;
138
138
  xmlXPathObjectPtr xmlValue;
@@ -154,28 +154,28 @@ register_variable(VALUE self, VALUE name, VALUE value)
154
154
  * returns Qundef if no conversion was possible.
155
155
  */
156
156
  static VALUE
157
- xpath2ruby(xmlXPathObjectPtr xobj, xmlXPathContextPtr xctx)
157
+ xpath2ruby(xmlXPathObjectPtr c_xpath_object, xmlXPathContextPtr ctx)
158
158
  {
159
- VALUE retval;
159
+ VALUE rb_retval;
160
160
 
161
- assert(xctx->doc);
162
- assert(DOC_RUBY_OBJECT_TEST(xctx->doc));
161
+ assert(ctx->doc);
162
+ assert(DOC_RUBY_OBJECT_TEST(ctx->doc));
163
163
 
164
- switch (xobj->type) {
164
+ switch (c_xpath_object->type) {
165
165
  case XPATH_STRING:
166
- retval = NOKOGIRI_STR_NEW2(xobj->stringval);
167
- xmlFree(xobj->stringval);
168
- return retval;
166
+ rb_retval = NOKOGIRI_STR_NEW2(c_xpath_object->stringval);
167
+ xmlFree(c_xpath_object->stringval);
168
+ return rb_retval;
169
169
 
170
170
  case XPATH_NODESET:
171
- return noko_xml_node_set_wrap(xobj->nodesetval,
172
- DOC_RUBY_OBJECT(xctx->doc));
171
+ return noko_xml_node_set_wrap(c_xpath_object->nodesetval,
172
+ DOC_RUBY_OBJECT(ctx->doc));
173
173
 
174
174
  case XPATH_NUMBER:
175
- return rb_float_new(xobj->floatval);
175
+ return rb_float_new(c_xpath_object->floatval);
176
176
 
177
177
  case XPATH_BOOLEAN:
178
- return (xobj->boolval == 1) ? Qtrue : Qfalse;
178
+ return (c_xpath_object->boolval == 1) ? Qtrue : Qfalse;
179
179
 
180
180
  default:
181
181
  return Qundef;
@@ -183,52 +183,51 @@ xpath2ruby(xmlXPathObjectPtr xobj, xmlXPathContextPtr xctx)
183
183
  }
184
184
 
185
185
  void
186
- Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler,
187
- const char *function_name)
186
+ Nokogiri_marshal_xpath_funcall_and_return_values(
187
+ xmlXPathParserContextPtr ctx,
188
+ int argc,
189
+ VALUE rb_xpath_handler,
190
+ const char *method_name
191
+ )
188
192
  {
189
- VALUE result, doc;
193
+ VALUE rb_retval;
190
194
  VALUE *argv;
191
- VALUE node_set = Qnil;
192
- xmlNodeSetPtr xml_node_set = NULL;
193
- xmlXPathObjectPtr obj;
195
+ VALUE rb_node_set = Qnil;
196
+ xmlNodeSetPtr c_node_set = NULL;
197
+ xmlXPathObjectPtr c_xpath_object;
194
198
 
195
199
  assert(ctx->context->doc);
196
200
  assert(DOC_RUBY_OBJECT_TEST(ctx->context->doc));
197
201
 
198
- argv = (VALUE *)calloc((size_t)nargs, sizeof(VALUE));
199
- for (int j = 0 ; j < nargs ; ++j) {
202
+ argv = (VALUE *)ruby_xcalloc((size_t)argc, sizeof(VALUE));
203
+ for (int j = 0 ; j < argc ; ++j) {
200
204
  rb_gc_register_address(&argv[j]);
201
205
  }
202
206
 
203
- doc = DOC_RUBY_OBJECT(ctx->context->doc);
204
-
205
- for (int j = nargs - 1 ; j >= 0 ; --j) {
206
- obj = valuePop(ctx);
207
- argv[j] = xpath2ruby(obj, ctx->context);
207
+ for (int j = argc - 1 ; j >= 0 ; --j) {
208
+ c_xpath_object = valuePop(ctx);
209
+ argv[j] = xpath2ruby(c_xpath_object, ctx->context);
208
210
  if (argv[j] == Qundef) {
209
- argv[j] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
211
+ argv[j] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(c_xpath_object));
210
212
  }
211
- xmlXPathFreeNodeSetList(obj);
213
+ xmlXPathFreeNodeSetList(c_xpath_object);
212
214
  }
213
215
 
214
- result = rb_funcall2(handler, rb_intern((const char *)function_name), nargs, argv);
216
+ rb_retval = rb_funcall2(rb_xpath_handler, rb_intern((const char *)method_name), argc, argv);
215
217
 
216
- for (int j = 0 ; j < nargs ; ++j) {
218
+ for (int j = 0 ; j < argc ; ++j) {
217
219
  rb_gc_unregister_address(&argv[j]);
218
220
  }
219
- free(argv);
221
+ ruby_xfree(argv);
220
222
 
221
- switch (TYPE(result)) {
223
+ switch (TYPE(rb_retval)) {
222
224
  case T_FLOAT:
223
225
  case T_BIGNUM:
224
226
  case T_FIXNUM:
225
- xmlXPathReturnNumber(ctx, NUM2DBL(result));
227
+ xmlXPathReturnNumber(ctx, NUM2DBL(rb_retval));
226
228
  break;
227
229
  case T_STRING:
228
- xmlXPathReturnString(
229
- ctx,
230
- xmlCharStrdup(StringValueCStr(result))
231
- );
230
+ xmlXPathReturnString(ctx, xmlCharStrdup(StringValueCStr(rb_retval)));
232
231
  break;
233
232
  case T_TRUE:
234
233
  xmlXPathReturnTrue(ctx);
@@ -239,19 +238,17 @@ Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, i
239
238
  case T_NIL:
240
239
  break;
241
240
  case T_ARRAY: {
242
- VALUE args[2];
243
- args[0] = doc;
244
- args[1] = result;
245
- node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
246
- Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
247
- xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
241
+ VALUE construct_args[2] = { DOC_RUBY_OBJECT(ctx->context->doc), rb_retval };
242
+ rb_node_set = rb_class_new_instance(2, construct_args, cNokogiriXmlNodeSet);
243
+ Data_Get_Struct(rb_node_set, xmlNodeSet, c_node_set);
244
+ xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, c_node_set));
248
245
  }
249
246
  break;
250
247
  case T_DATA:
251
- if (rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
252
- Data_Get_Struct(result, xmlNodeSet, xml_node_set);
248
+ if (rb_obj_is_kind_of(rb_retval, cNokogiriXmlNodeSet)) {
249
+ Data_Get_Struct(rb_retval, xmlNodeSet, c_node_set);
253
250
  /* Copy the node set, otherwise it will get GC'd. */
254
- xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
251
+ xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, c_node_set));
255
252
  break;
256
253
  }
257
254
  default:
@@ -260,47 +257,56 @@ Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, i
260
257
  }
261
258
 
262
259
  static void
263
- ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
260
+ method_caller(xmlXPathParserContextPtr ctx, int argc)
264
261
  {
265
- VALUE handler = Qnil;
266
- const char *function = NULL ;
262
+ VALUE rb_xpath_handler = Qnil;
263
+ const char *method_name = NULL ;
267
264
 
268
265
  assert(ctx);
269
266
  assert(ctx->context);
270
267
  assert(ctx->context->userData);
271
268
  assert(ctx->context->function);
272
269
 
273
- handler = (VALUE)(ctx->context->userData);
274
- function = (const char *)(ctx->context->function);
270
+ rb_xpath_handler = (VALUE)(ctx->context->userData);
271
+ method_name = (const char *)(ctx->context->function);
275
272
 
276
- Nokogiri_marshal_xpath_funcall_and_return_values(ctx, nargs, handler, function);
273
+ Nokogiri_marshal_xpath_funcall_and_return_values(ctx, argc, rb_xpath_handler, method_name);
277
274
  }
278
275
 
279
276
  static xmlXPathFunction
280
- lookup(void *ctx,
281
- const xmlChar *name,
282
- const xmlChar *ns_uri)
277
+ handler_lookup(void *ctx, const xmlChar *c_name, const xmlChar *c_ns_uri)
283
278
  {
284
- VALUE xpath_handler = (VALUE)ctx;
285
- if (rb_respond_to(xpath_handler, rb_intern((const char *)name))) {
286
- return ruby_funcall;
279
+ VALUE rb_xpath_handler = (VALUE)ctx;
280
+ if (rb_respond_to(rb_xpath_handler, rb_intern((const char *)c_name))) {
281
+ return method_caller;
287
282
  }
288
283
 
289
284
  return NULL;
290
285
  }
291
286
 
292
- NORETURN(static void xpath_generic_exception_handler(void *ctx, const char *msg, ...));
287
+ PRINTFLIKE_DECL(2, 3)
293
288
  static void
294
- xpath_generic_exception_handler(void *ctx, const char *msg, ...)
289
+ generic_exception_pusher(void *ctx, const char *msg, ...)
295
290
  {
296
- char *message;
291
+ VALUE rb_errors = (VALUE)ctx;
292
+ VALUE rb_message;
293
+ VALUE rb_exception;
294
+
295
+ Check_Type(rb_errors, T_ARRAY);
297
296
 
297
+ #ifdef TRUFFLERUBY_NOKOGIRI_SYSTEM_LIBRARIES
298
+ /* It is not currently possible to pass var args from native
299
+ functions to sulong, so we work around the issue here. */
300
+ rb_message = rb_sprintf("generic_exception_pusher: %s", msg);
301
+ #else
298
302
  va_list args;
299
303
  va_start(args, msg);
300
- vasprintf(&message, msg, args);
304
+ rb_message = rb_vsprintf(msg, args);
301
305
  va_end(args);
306
+ #endif
302
307
 
303
- rb_raise(rb_eRuntimeError, "%s", message);
308
+ rb_exception = rb_exc_new_str(cNokogiriXmlXpathSyntaxError, rb_message);
309
+ rb_ary_push(rb_errors, rb_exception);
304
310
  }
305
311
 
306
312
  /*
@@ -310,13 +316,14 @@ xpath_generic_exception_handler(void *ctx, const char *msg, ...)
310
316
  * Evaluate the +search_path+ returning an XML::XPath object.
311
317
  */
312
318
  static VALUE
313
- evaluate(int argc, VALUE *argv, VALUE self)
319
+ rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE self)
314
320
  {
315
321
  VALUE search_path, xpath_handler;
316
322
  VALUE retval = Qnil;
317
323
  xmlXPathContextPtr ctx;
318
324
  xmlXPathObjectPtr xpath;
319
325
  xmlChar *query;
326
+ VALUE errors = rb_ary_new();
320
327
 
321
328
  Data_Get_Struct(self, xmlXPathContext, ctx);
322
329
 
@@ -329,23 +336,19 @@ evaluate(int argc, VALUE *argv, VALUE self)
329
336
  if (Qnil != xpath_handler) {
330
337
  /* FIXME: not sure if this is the correct place to shove private data. */
331
338
  ctx->userData = (void *)xpath_handler;
332
- xmlXPathRegisterFuncLookup(ctx, lookup, (void *)xpath_handler);
339
+ xmlXPathRegisterFuncLookup(ctx, handler_lookup, (void *)xpath_handler);
333
340
  }
334
341
 
335
- xmlResetLastError();
336
- xmlSetStructuredErrorFunc(NULL, Nokogiri_error_raise);
337
-
338
- /* For some reason, xmlXPathEvalExpression will blow up with a generic error */
339
- /* when there is a non existent function. */
340
- xmlSetGenericErrorFunc(NULL, xpath_generic_exception_handler);
342
+ xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
343
+ xmlSetGenericErrorFunc((void *)errors, generic_exception_pusher);
341
344
 
342
345
  xpath = xmlXPathEvalExpression(query, ctx);
346
+
343
347
  xmlSetStructuredErrorFunc(NULL, NULL);
344
348
  xmlSetGenericErrorFunc(NULL, NULL);
345
349
 
346
350
  if (xpath == NULL) {
347
- xmlErrorPtr error = xmlGetLastError();
348
- rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
351
+ rb_exc_raise(rb_ary_entry(errors, 0));
349
352
  }
350
353
 
351
354
  retval = xpath2ruby(xpath, ctx);
@@ -365,26 +368,30 @@ evaluate(int argc, VALUE *argv, VALUE self)
365
368
  * Create a new XPathContext with +node+ as the reference point.
366
369
  */
367
370
  static VALUE
368
- new (VALUE klass, VALUE nodeobj)
371
+ rb_xml_xpath_context_new(VALUE klass, VALUE nodeobj)
369
372
  {
370
373
  xmlNodePtr node;
371
374
  xmlXPathContextPtr ctx;
372
375
  VALUE self;
373
376
 
374
- Data_Get_Struct(nodeobj, xmlNode, node);
377
+ Noko_Node_Get_Struct(nodeobj, xmlNode, node);
375
378
 
379
+ #if LIBXML_VERSION < 21000
380
+ /* deprecated in 40483d0 */
376
381
  xmlXPathInit();
382
+ #endif
377
383
 
378
384
  ctx = xmlXPathNewContext(node->doc);
379
385
  ctx->node = node;
380
386
 
387
+ xmlXPathRegisterNs(ctx, NOKOGIRI_PREFIX, NOKOGIRI_URI);
381
388
  xmlXPathRegisterNs(ctx, NOKOGIRI_BUILTIN_PREFIX, NOKOGIRI_BUILTIN_URI);
382
389
  xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"css-class", NOKOGIRI_BUILTIN_URI,
383
390
  xpath_builtin_css_class);
384
391
  xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"local-name-is", NOKOGIRI_BUILTIN_URI,
385
392
  xpath_builtin_local_name_is);
386
393
 
387
- self = Data_Wrap_Struct(klass, 0, deallocate, ctx);
394
+ self = Data_Wrap_Struct(klass, 0, xml_xpath_context_deallocate, ctx);
388
395
  return self;
389
396
  }
390
397
 
@@ -398,9 +405,9 @@ noko_init_xml_xpath_context(void)
398
405
 
399
406
  rb_undef_alloc_func(cNokogiriXmlXpathContext);
400
407
 
401
- rb_define_singleton_method(cNokogiriXmlXpathContext, "new", new, 1);
408
+ rb_define_singleton_method(cNokogiriXmlXpathContext, "new", rb_xml_xpath_context_new, 1);
402
409
 
403
- rb_define_method(cNokogiriXmlXpathContext, "evaluate", evaluate, -1);
404
- rb_define_method(cNokogiriXmlXpathContext, "register_variable", register_variable, 2);
405
- rb_define_method(cNokogiriXmlXpathContext, "register_ns", register_ns, 2);
410
+ rb_define_method(cNokogiriXmlXpathContext, "evaluate", rb_xml_xpath_context_evaluate, -1);
411
+ rb_define_method(cNokogiriXmlXpathContext, "register_variable", rb_xml_xpath_context_register_variable, 2);
412
+ rb_define_method(cNokogiriXmlXpathContext, "register_ns", rb_xml_xpath_context_register_ns, 2);
406
413
  }
@@ -12,27 +12,28 @@ static void
12
12
  dealloc(nokogiriXsltStylesheetTuple *wrapper)
13
13
  {
14
14
  xsltStylesheetPtr doc = wrapper->ss;
15
-
16
- NOKOGIRI_DEBUG_START(doc);
17
- xsltFreeStylesheet(doc); /* commented out for now. */
18
- NOKOGIRI_DEBUG_END(doc);
19
-
20
- free(wrapper);
15
+ xsltFreeStylesheet(doc);
16
+ ruby_xfree(wrapper);
21
17
  }
22
18
 
19
+ PRINTFLIKE_DECL(2, 3)
23
20
  static void
24
21
  xslt_generic_error_handler(void *ctx, const char *msg, ...)
25
22
  {
26
- char *message;
23
+ VALUE message;
27
24
 
25
+ #ifdef TRUFFLERUBY_NOKOGIRI_SYSTEM_LIBRARIES
26
+ /* It is not currently possible to pass var args from native
27
+ functions to sulong, so we work around the issue here. */
28
+ message = rb_sprintf("xslt_generic_error_handler: %s", msg);
29
+ #else
28
30
  va_list args;
29
31
  va_start(args, msg);
30
- vasprintf(&message, msg, args);
32
+ message = rb_vsprintf(msg, args);
31
33
  va_end(args);
34
+ #endif
32
35
 
33
- rb_str_cat2((VALUE)ctx, message);
34
-
35
- free(message);
36
+ rb_str_concat((VALUE)ctx, message);
36
37
  }
37
38
 
38
39
  VALUE
@@ -248,7 +249,7 @@ transform(int argc, VALUE *argv, VALUE self)
248
249
  Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
249
250
 
250
251
  param_len = RARRAY_LEN(paramobj);
251
- params = calloc((size_t)param_len + 1, sizeof(char *));
252
+ params = ruby_xcalloc((size_t)param_len + 1, sizeof(char *));
252
253
  for (j = 0 ; j < param_len ; j++) {
253
254
  VALUE entry = rb_ary_entry(paramobj, j);
254
255
  const char *ptr = StringValueCStr(entry);
@@ -261,7 +262,7 @@ transform(int argc, VALUE *argv, VALUE self)
261
262
  xmlSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
262
263
 
263
264
  result = xsltApplyStylesheet(wrapper->ss, xml, params);
264
- free(params);
265
+ ruby_xfree(params);
265
266
 
266
267
  xsltSetGenericErrorFunc(NULL, NULL);
267
268
  xmlSetGenericErrorFunc(NULL, NULL);
@@ -347,7 +348,7 @@ registr(VALUE self, VALUE uri, VALUE obj)
347
348
  }
348
349
 
349
350
  void
350
- noko_init_xslt_stylesheet()
351
+ noko_init_xslt_stylesheet(void)
351
352
  {
352
353
  rb_define_singleton_method(mNokogiriXslt, "register", registr, 2);
353
354
  rb_iv_set(mNokogiriXslt, "@modules", rb_hash_new());
@@ -13,8 +13,18 @@ LDFLAGS := -pthread
13
13
 
14
14
  all: check
15
15
 
16
+ # don't try to regenerate ragel or gperf files in CI, that should be a development-only action and
17
+ # the generated files should be committed to SCM
18
+ ifneq ($(CI),true)
19
+ src/foreign_attrs.c: src/foreign_attrs.gperf
20
+ gperf -m100 -n $< | ./gperf-filter.sed > $@
21
+
22
+ src/%.c: src/%.gperf
23
+ gperf -m100 $< | ./gperf-filter.sed > $@
24
+
16
25
  src/%.c: src/%.rl
17
26
  ragel -F1 -o $@ $<
27
+ endif
18
28
 
19
29
  build/src:
20
30
  mkdir -p $@
@@ -1,7 +1,7 @@
1
1
  #ifndef GUMBO_ATTRIBUTE_H_
2
2
  #define GUMBO_ATTRIBUTE_H_
3
3
 
4
- #include "gumbo.h"
4
+ #include "nokogiri_gumbo.h"
5
5
 
6
6
  #ifdef __cplusplus
7
7
  extern "C" {
@@ -21,7 +21,7 @@
21
21
  #include <string.h>
22
22
  #include "ascii.h"
23
23
  #include "error.h"
24
- #include "gumbo.h"
24
+ #include "nokogiri_gumbo.h"
25
25
  #include "macros.h"
26
26
  #include "parser.h"
27
27
  #include "string_buffer.h"
@@ -96,7 +96,7 @@ static void print_tag_stack (
96
96
  if (i) {
97
97
  print_message(output, ", ");
98
98
  }
99
- GumboTag tag = (GumboTag) error->tag_stack.data[i];
99
+ GumboTag tag = (GumboTag)(intptr_t) error->tag_stack.data[i];
100
100
  print_message(output, "%s", gumbo_normalized_tagname(tag));
101
101
  }
102
102
  gumbo_string_buffer_append_codepoint('.', output);
@@ -3,7 +3,7 @@
3
3
 
4
4
  #include <stdint.h>
5
5
 
6
- #include "gumbo.h"
6
+ #include "nokogiri_gumbo.h"
7
7
  #include "insertion_mode.h"
8
8
  #include "string_buffer.h"
9
9
  #include "token_type.h"
@@ -1,7 +1,7 @@
1
1
  /* ANSI-C code produced by gperf version 3.1 */
2
- /* Command-line: gperf -m100 -n lib/foreign_attrs.gperf */
2
+ /* Command-line: gperf -m100 -n src/foreign_attrs.gperf */
3
3
  /* Computed positions: -k'2,8' */
4
- /* Filtered by: mk/gperf-filter.sed */
4
+ /* Filtered by: gperf-filter.sed */
5
5
 
6
6
  #include "replacement.h"
7
7
  #include "macros.h"
@@ -292,6 +292,7 @@ typedef enum {
292
292
  GUMBO_TAG_TT,
293
293
  GUMBO_TAG_RTC,
294
294
  GUMBO_TAG_DIALOG,
295
+ GUMBO_TAG_SEARCH,
295
296
  // Used for all tags that don't have special handling in HTML.
296
297
  GUMBO_TAG_UNKNOWN,
297
298
  // A marker value to indicate the end of the enum, for iterating over it.
@@ -24,7 +24,7 @@
24
24
  #include "ascii.h"
25
25
  #include "attribute.h"
26
26
  #include "error.h"
27
- #include "gumbo.h"
27
+ #include "nokogiri_gumbo.h"
28
28
  #include "insertion_mode.h"
29
29
  #include "macros.h"
30
30
  #include "parser.h"
@@ -537,7 +537,7 @@ static GumboInsertionMode get_current_template_insertion_mode (
537
537
  if (modes->length == 0) {
538
538
  return GUMBO_INSERTION_MODE_INITIAL;
539
539
  }
540
- return (GumboInsertionMode) modes->data[(modes->length - 1)];
540
+ return (GumboInsertionMode)(intptr_t) modes->data[(modes->length - 1)];
541
541
  }
542
542
 
543
543
  // Returns true if the specified token is either a start or end tag
@@ -2940,7 +2940,7 @@ static void handle_in_body(GumboParser* parser, GumboToken* token) {
2940
2940
  TAG(DETAILS), TAG(DIALOG), TAG(DIR), TAG(DIV), TAG(DL), TAG(FIELDSET),
2941
2941
  TAG(FIGCAPTION), TAG(FIGURE), TAG(FOOTER), TAG(HEADER), TAG(HGROUP),
2942
2942
  TAG(MAIN), TAG(MENU), TAG(NAV), TAG(OL), TAG(P), TAG(SECTION),
2943
- TAG(SUMMARY), TAG(UL)
2943
+ TAG(SUMMARY), TAG(UL), TAG(SEARCH)
2944
2944
  })
2945
2945
  ) {
2946
2946
  maybe_implicitly_close_p_tag(parser, token);
@@ -3018,7 +3018,7 @@ static void handle_in_body(GumboParser* parser, GumboToken* token) {
3018
3018
  TAG(CENTER), TAG(DETAILS), TAG(DIALOG), TAG(DIR), TAG(DIV), TAG(DL),
3019
3019
  TAG(FIELDSET), TAG(FIGCAPTION), TAG(FIGURE), TAG(FOOTER), TAG(HEADER),
3020
3020
  TAG(HGROUP), TAG(LISTING), TAG(MAIN), TAG(MENU), TAG(NAV), TAG(OL),
3021
- TAG(PRE), TAG(SECTION), TAG(SUMMARY), TAG(UL)
3021
+ TAG(PRE), TAG(SECTION), TAG(SUMMARY), TAG(UL), TAG(SEARCH)
3022
3022
  })
3023
3023
  ) {
3024
3024
  GumboTag tag = token->v.end_tag.tag;
@@ -3057,6 +3057,9 @@ static void handle_in_body(GumboParser* parser, GumboToken* token) {
3057
3057
  ignore_token(parser);
3058
3058
  return;
3059
3059
  }
3060
+ // Since we remove the form node without popping, we need to make sure
3061
+ // that we flush any text nodes at the end of the form.
3062
+ maybe_flush_text_node_buffer(parser);
3060
3063
  // This differs from implicitly_close_tags because we remove *only* the
3061
3064
  // <form> element; other nodes are left in scope.
3062
3065
  generate_implied_end_tags(parser, GUMBO_TAG_LAST, NULL);
@@ -3434,7 +3437,7 @@ static void handle_in_table(GumboParser* parser, GumboToken* token) {
3434
3437
  || token->type == GUMBO_TOKEN_WHITESPACE
3435
3438
  || token->type == GUMBO_TOKEN_NULL)
3436
3439
  && node_tag_in_set(get_current_node(parser), &(const TagSet) {
3437
- TAG(TABLE), TAG(TBODY), TAG(TFOOT), TAG(THEAD), TAG(TR)
3440
+ TAG(TABLE), TAG(TBODY), TAG(TEMPLATE), TAG(TFOOT), TAG(THEAD), TAG(TR)
3438
3441
  })
3439
3442
  ) {
3440
3443
  // The "pending table character tokens" list described in the spec is
@@ -2,7 +2,7 @@
2
2
  #define GUMBO_REPLACEMENT_H_
3
3
 
4
4
  #include <stddef.h>
5
- #include "gumbo.h"
5
+ #include "nokogiri_gumbo.h"
6
6
 
7
7
  typedef struct {
8
8
  const char *const from;
@@ -4,7 +4,7 @@
4
4
  #include <stdbool.h>
5
5
  #include <stddef.h>
6
6
 
7
- #include "gumbo.h"
7
+ #include "nokogiri_gumbo.h"
8
8
 
9
9
  #ifdef __cplusplus
10
10
  extern "C" {
@@ -17,7 +17,7 @@
17
17
 
18
18
  #include <stddef.h>
19
19
  #include <string.h>
20
- #include "gumbo.h"
20
+ #include "nokogiri_gumbo.h"
21
21
  #include "ascii.h"
22
22
 
23
23
  bool gumbo_string_equals (
@@ -1,7 +1,7 @@
1
1
  /* ANSI-C code produced by gperf version 3.1 */
2
- /* Command-line: gperf -m100 lib/svg_attrs.gperf */
2
+ /* Command-line: gperf -m100 src/svg_attrs.gperf */
3
3
  /* Computed positions: -k'1,10,$' */
4
- /* Filtered by: mk/gperf-filter.sed */
4
+ /* Filtered by: gperf-filter.sed */
5
5
 
6
6
  #include "replacement.h"
7
7
  #include "macros.h"
@@ -1,7 +1,7 @@
1
1
  /* ANSI-C code produced by gperf version 3.1 */
2
- /* Command-line: gperf -m100 lib/svg_tags.gperf */
2
+ /* Command-line: gperf -m100 src/svg_tags.gperf */
3
3
  /* Computed positions: -k'3,7' */
4
- /* Filtered by: mk/gperf-filter.sed */
4
+ /* Filtered by: gperf-filter.sed */
5
5
 
6
6
  #include "replacement.h"
7
7
  #include "macros.h"
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- #include "gumbo.h"
17
+ #include "nokogiri_gumbo.h"
18
18
  #include "util.h"
19
19
  #include "tag_lookup.h"
20
20
 
@@ -172,6 +172,7 @@ static const char kGumboTagNames[GUMBO_TAG_LAST+1][15] = {
172
172
  [GUMBO_TAG_TT] = "tt",
173
173
  [GUMBO_TAG_RTC] = "rtc",
174
174
  [GUMBO_TAG_DIALOG] = "dialog",
175
+ [GUMBO_TAG_SEARCH] = "search",
175
176
 
176
177
  [GUMBO_TAG_UNKNOWN] = "",
177
178
  [GUMBO_TAG_LAST] = "",
@@ -1,14 +1,14 @@
1
1
  /* ANSI-C code produced by gperf version 3.1 */
2
- /* Command-line: gperf -m100 lib/tag_lookup.gperf */
2
+ /* Command-line: gperf -m100 src/tag_lookup.gperf */
3
3
  /* Computed positions: -k'1-2,$' */
4
- /* Filtered by: mk/gperf-filter.sed */
4
+ /* Filtered by: gperf-filter.sed */
5
5
 
6
6
  #include "tag_lookup.h"
7
7
  #include "macros.h"
8
8
  #include "ascii.h"
9
9
  #include <string.h>
10
10
 
11
- #define TOTAL_KEYWORDS 150
11
+ #define TOTAL_KEYWORDS 151
12
12
  #define MIN_WORD_LENGTH 1
13
13
  #define MAX_WORD_LENGTH 14
14
14
  #define MIN_HASH_VALUE 9
@@ -26,7 +26,7 @@ hash (register const char *str, register size_t len)
26
26
  272, 272, 272, 272, 272, 272, 272, 272, 272, 272,
27
27
  272, 272, 272, 272, 272, 272, 272, 272, 272, 272,
28
28
  272, 272, 272, 272, 272, 272, 272, 272, 272, 272,
29
- 272, 272, 272, 272, 272, 272, 272, 272, 272, 9,
29
+ 272, 272, 272, 272, 272, 272, 272, 272, 272, 11,
30
30
  7, 6, 4, 4, 3, 4, 3, 3, 272, 272,
31
31
  272, 272, 272, 272, 272, 70, 83, 152, 7, 16,
32
32
  61, 98, 5, 76, 102, 126, 12, 19, 54, 54,
@@ -69,7 +69,7 @@ gumbo_tag_lookup (register const char *str, register size_t len)
69
69
  static const unsigned char lengthtable[] =
70
70
  {
71
71
  0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2,
72
- 2, 2, 2, 6, 2, 6, 2, 4, 0, 7, 6, 3, 0, 3,
72
+ 2, 2, 2, 6, 2, 6, 6, 4, 2, 7, 6, 3, 0, 3,
73
73
  0, 6, 6, 8, 5, 0, 0, 4, 5, 5, 8, 0, 2, 4,
74
74
  5, 2, 0, 5, 4, 2, 0, 7, 0, 8, 5, 0, 0, 0,
75
75
  0, 0, 0, 5, 3, 4, 5, 1, 4, 0, 4, 1, 2, 8,
@@ -111,9 +111,9 @@ gumbo_tag_lookup (register const char *str, register size_t len)
111
111
  {"spacer", GUMBO_TAG_SPACER},
112
112
  {"h2", GUMBO_TAG_H2},
113
113
  {"header", GUMBO_TAG_HEADER},
114
- {"h1", GUMBO_TAG_H1},
114
+ {"search", GUMBO_TAG_SEARCH},
115
115
  {"head", GUMBO_TAG_HEAD},
116
- {(char*)0,GUMBO_TAG_UNKNOWN},
116
+ {"h1", GUMBO_TAG_H1},
117
117
  {"details", GUMBO_TAG_DETAILS},
118
118
  {"select", GUMBO_TAG_SELECT},
119
119
  {"dir", GUMBO_TAG_DIR},
@@ -167,3 +167,4 @@ spacer, GUMBO_TAG_SPACER
167
167
  tt, GUMBO_TAG_TT
168
168
  rtc, GUMBO_TAG_RTC
169
169
  dialog, GUMBO_TAG_DIALOG
170
+ search, GUMBO_TAG_SEARCH