nokogiri 1.13.10-java → 1.14.0-java

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 (119) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +33 -0
  3. data/LICENSE-DEPENDENCIES.md +830 -509
  4. data/LICENSE.md +1 -1
  5. data/README.md +18 -11
  6. data/dependencies.yml +25 -7
  7. data/ext/java/nokogiri/Html4Document.java +2 -0
  8. data/ext/java/nokogiri/Html4ElementDescription.java +9 -9
  9. data/ext/java/nokogiri/Html4EntityLookup.java +14 -3
  10. data/ext/java/nokogiri/Html4SaxParserContext.java +2 -2
  11. data/ext/java/nokogiri/Html4SaxPushParser.java +3 -0
  12. data/ext/java/nokogiri/NokogiriService.java +1 -24
  13. data/ext/java/nokogiri/XmlAttr.java +1 -1
  14. data/ext/java/nokogiri/XmlAttributeDecl.java +2 -1
  15. data/ext/java/nokogiri/XmlCdata.java +2 -1
  16. data/ext/java/nokogiri/XmlComment.java +2 -1
  17. data/ext/java/nokogiri/XmlDocument.java +5 -6
  18. data/ext/java/nokogiri/XmlDocumentFragment.java +2 -1
  19. data/ext/java/nokogiri/XmlDtd.java +4 -3
  20. data/ext/java/nokogiri/XmlElement.java +1 -0
  21. data/ext/java/nokogiri/XmlElementContent.java +4 -1
  22. data/ext/java/nokogiri/XmlElementDecl.java +3 -1
  23. data/ext/java/nokogiri/XmlEntityDecl.java +2 -0
  24. data/ext/java/nokogiri/XmlEntityReference.java +1 -0
  25. data/ext/java/nokogiri/XmlNamespace.java +2 -0
  26. data/ext/java/nokogiri/XmlNode.java +39 -24
  27. data/ext/java/nokogiri/XmlNodeSet.java +10 -7
  28. data/ext/java/nokogiri/XmlProcessingInstruction.java +1 -0
  29. data/ext/java/nokogiri/XmlReader.java +4 -3
  30. data/ext/java/nokogiri/XmlRelaxng.java +1 -0
  31. data/ext/java/nokogiri/XmlSaxParserContext.java +1 -0
  32. data/ext/java/nokogiri/XmlSaxPushParser.java +3 -0
  33. data/ext/java/nokogiri/XmlSchema.java +4 -2
  34. data/ext/java/nokogiri/XmlSyntaxError.java +1 -0
  35. data/ext/java/nokogiri/XmlText.java +1 -0
  36. data/ext/java/nokogiri/XmlXpathContext.java +2 -0
  37. data/ext/java/nokogiri/XsltStylesheet.java +16 -13
  38. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +3 -2
  39. data/ext/java/nokogiri/internals/NokogiriHandler.java +2 -2
  40. data/ext/java/nokogiri/internals/NokogiriHelpers.java +4 -5
  41. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +3 -3
  42. data/ext/java/nokogiri/internals/ParserContext.java +2 -0
  43. data/ext/java/nokogiri/internals/ReaderNode.java +1 -1
  44. data/ext/java/nokogiri/internals/SaveContextVisitor.java +4 -2
  45. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +2 -2
  46. data/ext/java/nokogiri/internals/XmlDomParserContext.java +2 -1
  47. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +1 -0
  48. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +5 -4
  49. data/ext/nokogiri/extconf.rb +80 -21
  50. data/ext/nokogiri/gumbo.c +19 -9
  51. data/ext/nokogiri/html4_document.c +1 -1
  52. data/ext/nokogiri/html4_entity_lookup.c +1 -1
  53. data/ext/nokogiri/html4_sax_parser_context.c +0 -5
  54. data/ext/nokogiri/nokogiri.c +33 -51
  55. data/ext/nokogiri/xml_attribute_decl.c +1 -1
  56. data/ext/nokogiri/xml_cdata.c +1 -1
  57. data/ext/nokogiri/xml_document.c +16 -11
  58. data/ext/nokogiri/xml_element_content.c +2 -2
  59. data/ext/nokogiri/xml_element_decl.c +1 -1
  60. data/ext/nokogiri/xml_encoding_handler.c +2 -2
  61. data/ext/nokogiri/xml_namespace.c +38 -8
  62. data/ext/nokogiri/xml_node.c +286 -26
  63. data/ext/nokogiri/xml_node_set.c +0 -2
  64. data/ext/nokogiri/xml_reader.c +40 -20
  65. data/ext/nokogiri/xml_relax_ng.c +0 -2
  66. data/ext/nokogiri/xml_sax_parser.c +22 -16
  67. data/ext/nokogiri/xml_sax_parser_context.c +0 -5
  68. data/ext/nokogiri/xml_sax_push_parser.c +0 -2
  69. data/ext/nokogiri/xml_schema.c +0 -2
  70. data/ext/nokogiri/xml_xpath_context.c +87 -83
  71. data/ext/nokogiri/xslt_stylesheet.c +14 -13
  72. data/gumbo-parser/Makefile +10 -0
  73. data/lib/nokogiri/css/node.rb +2 -2
  74. data/lib/nokogiri/css/xpath_visitor.rb +5 -3
  75. data/lib/nokogiri/css.rb +6 -0
  76. data/lib/nokogiri/encoding_handler.rb +57 -0
  77. data/lib/nokogiri/extension.rb +3 -2
  78. data/lib/nokogiri/html4/document.rb +2 -121
  79. data/lib/nokogiri/html4/element_description_defaults.rb +6 -12
  80. data/lib/nokogiri/html4/encoding_reader.rb +121 -0
  81. data/lib/nokogiri/html4.rb +1 -0
  82. data/lib/nokogiri/html5/document.rb +113 -36
  83. data/lib/nokogiri/html5/document_fragment.rb +9 -2
  84. data/lib/nokogiri/html5/node.rb +3 -5
  85. data/lib/nokogiri/html5.rb +127 -216
  86. data/lib/nokogiri/jruby/dependencies.rb +1 -19
  87. data/lib/{isorelax.jar → nokogiri/jruby/isorelax/isorelax/20030108/isorelax-20030108.jar} +0 -0
  88. data/lib/nokogiri/jruby/net/sf/saxon/Saxon-HE/9.6.0-4/Saxon-HE-9.6.0-4.jar +0 -0
  89. data/lib/nokogiri/jruby/net/sourceforge/htmlunit/neko-htmlunit/2.63.0/neko-htmlunit-2.63.0.jar +0 -0
  90. data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
  91. data/lib/nokogiri/jruby/nu/validator/jing/20200702VNU/jing-20200702VNU.jar +0 -0
  92. data/lib/nokogiri/jruby/org/nokogiri/nekodtd/0.1.11.noko1/nekodtd-0.1.11.noko1.jar +0 -0
  93. data/lib/{serializer.jar → nokogiri/jruby/xalan/serializer/2.7.2/serializer-2.7.2.jar} +0 -0
  94. data/lib/{xalan.jar → nokogiri/jruby/xalan/xalan/2.7.2/xalan-2.7.2.jar} +0 -0
  95. data/lib/{xercesImpl.jar → nokogiri/jruby/xerces/xercesImpl/2.12.2/xercesImpl-2.12.2.jar} +0 -0
  96. data/lib/{xml-apis.jar → nokogiri/jruby/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar} +0 -0
  97. data/lib/nokogiri/nokogiri.jar +0 -0
  98. data/lib/nokogiri/version/constant.rb +1 -1
  99. data/lib/nokogiri/version/info.rb +11 -10
  100. data/lib/nokogiri/xml/attr.rb +49 -0
  101. data/lib/nokogiri/xml/builder.rb +1 -1
  102. data/lib/nokogiri/xml/document.rb +102 -54
  103. data/lib/nokogiri/xml/document_fragment.rb +49 -6
  104. data/lib/nokogiri/xml/namespace.rb +42 -0
  105. data/lib/nokogiri/xml/node/save_options.rb +6 -4
  106. data/lib/nokogiri/xml/node.rb +190 -35
  107. data/lib/nokogiri/xml/node_set.rb +87 -9
  108. data/lib/nokogiri/xml/parse_options.rb +129 -50
  109. data/lib/nokogiri/xml/pp/node.rb +6 -4
  110. data/lib/nokogiri/xml/processing_instruction.rb +2 -1
  111. data/lib/nokogiri/xml/sax/parser.rb +2 -3
  112. data/lib/nokogiri/xslt.rb +1 -1
  113. data/lib/nokogiri.rb +3 -11
  114. data/lib/xsd/xmlparser/nokogiri.rb +3 -1
  115. metadata +60 -272
  116. data/ext/java/nokogiri/EncodingHandler.java +0 -111
  117. data/lib/jing.jar +0 -0
  118. data/lib/nekodtd.jar +0 -0
  119. data/lib/nekohtml.jar +0 -0
@@ -7,13 +7,8 @@ static ID id_read;
7
7
  static void
8
8
  deallocate(xmlParserCtxtPtr ctxt)
9
9
  {
10
- NOKOGIRI_DEBUG_START(ctxt);
11
-
12
10
  ctxt->sax = NULL;
13
-
14
11
  xmlFreeParserCtxt(ctxt);
15
-
16
- NOKOGIRI_DEBUG_END(ctxt);
17
12
  }
18
13
 
19
14
  /*
@@ -5,12 +5,10 @@ VALUE cNokogiriXmlSaxPushParser ;
5
5
  static void
6
6
  deallocate(xmlParserCtxtPtr ctx)
7
7
  {
8
- NOKOGIRI_DEBUG_START(ctx);
9
8
  if (ctx != NULL) {
10
9
  NOKOGIRI_SAX_TUPLE_DESTROY(ctx->userData);
11
10
  xmlFreeParserCtxt(ctx);
12
11
  }
13
- NOKOGIRI_DEBUG_END(ctx);
14
12
  }
15
13
 
16
14
  static VALUE
@@ -5,9 +5,7 @@ VALUE cNokogiriXmlSchema;
5
5
  static void
6
6
  dealloc(xmlSchemaPtr schema)
7
7
  {
8
- NOKOGIRI_DEBUG_START(schema);
9
8
  xmlSchemaFree(schema);
10
- NOKOGIRI_DEBUG_END(schema);
11
9
  }
12
10
 
13
11
  /*
@@ -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,7 +368,7 @@ 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;
@@ -381,13 +384,14 @@ new (VALUE klass, VALUE nodeobj)
381
384
  ctx = xmlXPathNewContext(node->doc);
382
385
  ctx->node = node;
383
386
 
387
+ xmlXPathRegisterNs(ctx, NOKOGIRI_PREFIX, NOKOGIRI_URI);
384
388
  xmlXPathRegisterNs(ctx, NOKOGIRI_BUILTIN_PREFIX, NOKOGIRI_BUILTIN_URI);
385
389
  xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"css-class", NOKOGIRI_BUILTIN_URI,
386
390
  xpath_builtin_css_class);
387
391
  xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"local-name-is", NOKOGIRI_BUILTIN_URI,
388
392
  xpath_builtin_local_name_is);
389
393
 
390
- self = Data_Wrap_Struct(klass, 0, deallocate, ctx);
394
+ self = Data_Wrap_Struct(klass, 0, xml_xpath_context_deallocate, ctx);
391
395
  return self;
392
396
  }
393
397
 
@@ -401,9 +405,9 @@ noko_init_xml_xpath_context(void)
401
405
 
402
406
  rb_undef_alloc_func(cNokogiriXmlXpathContext);
403
407
 
404
- rb_define_singleton_method(cNokogiriXmlXpathContext, "new", new, 1);
408
+ rb_define_singleton_method(cNokogiriXmlXpathContext, "new", rb_xml_xpath_context_new, 1);
405
409
 
406
- rb_define_method(cNokogiriXmlXpathContext, "evaluate", evaluate, -1);
407
- rb_define_method(cNokogiriXmlXpathContext, "register_variable", register_variable, 2);
408
- 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);
409
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);
@@ -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 $@
@@ -40,9 +40,9 @@ module Nokogiri
40
40
 
41
41
  # Convert to_type
42
42
  def to_type
43
- [@type] + @value.map do |n|
43
+ [@type] + @value.filter_map do |n|
44
44
  n.to_type if n.respond_to?(:to_type)
45
- end.compact
45
+ end
46
46
  end
47
47
 
48
48
  # Convert to array
@@ -230,11 +230,11 @@ module Nokogiri
230
230
  "descendant_selector" => "//",
231
231
  "child_selector" => "/",
232
232
  }.each do |k, v|
233
- class_eval %{
233
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
234
234
  def visit_#{k} node
235
235
  "\#{node.value.first.accept(self) if node.value.first}#{v}\#{node.value.last.accept(self)}"
236
236
  end
237
- }
237
+ RUBY
238
238
  end
239
239
 
240
240
  def visit_conditional_selector(node)
@@ -278,7 +278,9 @@ module Nokogiri
278
278
  end
279
279
 
280
280
  def nth(node, options = {})
281
- raise ArgumentError, "expected an+b node to contain 4 tokens, but is #{node.value.inspect}" unless node.value.size == 4
281
+ unless node.value.size == 4
282
+ raise(ArgumentError, "expected an+b node to contain 4 tokens, but is #{node.value.inspect}")
283
+ end
282
284
 
283
285
  a, b = read_a_and_positive_b(node.value)
284
286
  position = if options[:child]
data/lib/nokogiri/css.rb CHANGED
@@ -40,9 +40,15 @@ module Nokogiri
40
40
  # 💡 Note that translated queries are cached for performance concerns.
41
41
  #
42
42
  def xpath_for(selector, options = {})
43
+ raise TypeError, "no implicit conversion of #{selector.inspect} to String" unless selector.respond_to?(:to_str)
44
+
45
+ selector = selector.to_str
46
+ raise Nokogiri::CSS::SyntaxError, "empty CSS selector" if selector.empty?
47
+
43
48
  prefix = options.fetch(:prefix, Nokogiri::XML::XPath::GLOBAL_SEARCH_PREFIX)
44
49
  visitor = options.fetch(:visitor) { Nokogiri::CSS::XPathVisitor.new }
45
50
  ns = options.fetch(:ns, {})
51
+
46
52
  Parser.new(ns).xpath_for(selector, prefix, visitor)
47
53
  end
48
54
  end
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Nokogiri
5
+ class EncodingHandler
6
+ # Popular encoding aliases not known by all iconv implementations that Nokogiri should support.
7
+ USEFUL_ALIASES = {
8
+ # alias_name => true_name
9
+ "NOKOGIRI-SENTINEL" => "UTF-8", # indicating the Nokogiri has installed aliases
10
+ "Windows-31J" => "CP932", # Windows-31J is the IANA registered name of CP932.
11
+ "UTF-8" => "UTF-8", # for JRuby tests, this is a no-op in CRuby
12
+ }
13
+
14
+ class << self
15
+ def install_default_aliases
16
+ USEFUL_ALIASES.each do |alias_name, name|
17
+ EncodingHandler.alias(name, alias_name) if EncodingHandler[alias_name].nil?
18
+ end
19
+ end
20
+ end
21
+
22
+ # :stopdoc:
23
+ if Nokogiri.jruby?
24
+ class << self
25
+ def [](name)
26
+ storage.key?(name) ? new(storage[name]) : nil
27
+ end
28
+
29
+ def alias(name, alias_name)
30
+ storage[alias_name] = name
31
+ end
32
+
33
+ def delete(name)
34
+ storage.delete(name)
35
+ end
36
+
37
+ def clear_aliases!
38
+ storage.clear
39
+ end
40
+
41
+ private
42
+
43
+ def storage
44
+ @storage ||= {}
45
+ end
46
+ end
47
+
48
+ def initialize(name)
49
+ @name = name
50
+ end
51
+
52
+ attr_reader :name
53
+ end
54
+ end
55
+ end
56
+
57
+ Nokogiri::EncodingHandler.install_default_aliases
@@ -3,13 +3,14 @@
3
3
  # load the C or Java extension
4
4
  begin
5
5
  # native precompiled gems package shared libraries in <gem_dir>/lib/nokogiri/<ruby_version>
6
- ::RUBY_VERSION =~ /(\d+\.\d+)/
6
+ RUBY_VERSION =~ /(\d+\.\d+)/
7
7
  require_relative "#{Regexp.last_match(1)}/nokogiri"
8
8
  rescue LoadError => e
9
9
  if /GLIBC/.match?(e.message)
10
10
  warn(<<~EOM)
11
11
 
12
- ERROR: It looks like you're trying to use Nokogiri as a precompiled native gem on a system with glibc < 2.17:
12
+ ERROR: It looks like you're trying to use Nokogiri as a precompiled native gem on a system
13
+ with an unsupported version of glibc.
13
14
 
14
15
  #{e.message}
15
16