nokogiri 1.14.4-x86_64-linux → 1.15.0-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +9 -8
- data/dependencies.yml +6 -6
- data/ext/nokogiri/extconf.rb +66 -22
- data/ext/nokogiri/html4_document.c +1 -2
- data/ext/nokogiri/html4_element_description.c +19 -14
- data/ext/nokogiri/html4_sax_parser_context.c +10 -16
- data/ext/nokogiri/html4_sax_push_parser.c +2 -2
- data/ext/nokogiri/include/libexslt/exsltconfig.h +3 -3
- data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +52 -38
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +18 -18
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +36 -36
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +37 -36
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +4 -4
- data/ext/nokogiri/include/libxml2/libxml/catalog.h +36 -36
- data/ext/nokogiri/include/libxml2/libxml/chvalid.h +9 -9
- data/ext/nokogiri/include/libxml2/libxml/debugXML.h +28 -28
- data/ext/nokogiri/include/libxml2/libxml/dict.h +13 -13
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +20 -19
- data/ext/nokogiri/include/libxml2/libxml/entities.h +19 -21
- data/ext/nokogiri/include/libxml2/libxml/globals.h +89 -59
- data/ext/nokogiri/include/libxml2/libxml/hash.h +25 -25
- data/ext/nokogiri/include/libxml2/libxml/list.h +26 -26
- data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +22 -22
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +17 -17
- data/ext/nokogiri/include/libxml2/libxml/parser.h +100 -79
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +149 -143
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +15 -15
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +26 -26
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +2 -2
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +18 -18
- data/ext/nokogiri/include/libxml2/libxml/threads.h +23 -20
- data/ext/nokogiri/include/libxml2/libxml/tree.h +166 -164
- data/ext/nokogiri/include/libxml2/libxml/uri.h +15 -15
- data/ext/nokogiri/include/libxml2/libxml/valid.h +72 -87
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +10 -10
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +5 -5
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +60 -59
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +21 -21
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +18 -46
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +14 -41
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +26 -24
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +4 -4
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +87 -87
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +30 -30
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +10 -10
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +30 -30
- data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +34 -34
- data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +30 -30
- data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +166 -166
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +50 -27
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +80 -80
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +41 -41
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +117 -117
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +21 -21
- data/ext/nokogiri/include/libxslt/attributes.h +1 -0
- data/ext/nokogiri/include/libxslt/variables.h +3 -3
- data/ext/nokogiri/include/libxslt/xsltInternals.h +14 -4
- data/ext/nokogiri/include/libxslt/xsltconfig.h +4 -4
- data/ext/nokogiri/include/libxslt/xsltlocale.h +14 -54
- data/ext/nokogiri/include/libxslt/xsltutils.h +35 -2
- data/ext/nokogiri/nokogiri.c +46 -24
- data/ext/nokogiri/nokogiri.h +13 -2
- data/ext/nokogiri/xml_attr.c +1 -1
- data/ext/nokogiri/xml_cdata.c +10 -2
- data/ext/nokogiri/xml_comment.c +1 -1
- data/ext/nokogiri/xml_document.c +102 -22
- data/ext/nokogiri/xml_document_fragment.c +1 -1
- data/ext/nokogiri/xml_dtd.c +1 -1
- data/ext/nokogiri/xml_element_content.c +32 -29
- data/ext/nokogiri/xml_element_decl.c +5 -5
- data/ext/nokogiri/xml_encoding_handler.c +12 -4
- data/ext/nokogiri/xml_entity_reference.c +1 -1
- data/ext/nokogiri/xml_namespace.c +11 -12
- data/ext/nokogiri/xml_node.c +7 -7
- data/ext/nokogiri/xml_node_set.c +125 -105
- data/ext/nokogiri/xml_processing_instruction.c +1 -1
- data/ext/nokogiri/xml_reader.c +37 -28
- data/ext/nokogiri/xml_relax_ng.c +65 -78
- data/ext/nokogiri/xml_sax_parser.c +24 -5
- data/ext/nokogiri/xml_sax_parser_context.c +46 -25
- data/ext/nokogiri/xml_sax_push_parser.c +29 -8
- data/ext/nokogiri/xml_schema.c +90 -116
- data/ext/nokogiri/xml_text.c +10 -2
- data/ext/nokogiri/xml_xpath_context.c +156 -83
- data/ext/nokogiri/xslt_stylesheet.c +103 -50
- data/lib/nokogiri/2.7/nokogiri.so +0 -0
- data/lib/nokogiri/3.0/nokogiri.so +0 -0
- data/lib/nokogiri/3.1/nokogiri.so +0 -0
- data/lib/nokogiri/3.2/nokogiri.so +0 -0
- data/lib/nokogiri/css/xpath_visitor.rb +2 -2
- data/lib/nokogiri/extension.rb +1 -1
- data/lib/nokogiri/html4/document_fragment.rb +1 -1
- data/lib/nokogiri/html4/element_description_defaults.rb +1821 -353
- data/lib/nokogiri/html5/document_fragment.rb +1 -1
- data/lib/nokogiri/html5/node.rb +5 -0
- data/lib/nokogiri/html5.rb +5 -2
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/xml/attribute_decl.rb +4 -2
- data/lib/nokogiri/xml/document_fragment.rb +1 -1
- data/lib/nokogiri/xml/element_content.rb +10 -2
- data/lib/nokogiri/xml/element_decl.rb +4 -2
- data/lib/nokogiri/xml/entity_decl.rb +4 -2
- data/lib/nokogiri/xml/node/save_options.rb +8 -0
- data/lib/nokogiri/xml/node.rb +22 -13
- data/lib/nokogiri/xml/pp/node.rb +23 -12
- data/lib/nokogiri/xml/sax/document.rb +1 -1
- data/lib/nokogiri/xml/searchable.rb +18 -10
- data/lib/nokogiri/xslt.rb +73 -3
- data/lib/nokogiri.rb +12 -4
- data/lib/xsd/xmlparser/nokogiri.rb +1 -1
- metadata +2 -2
@@ -12,11 +12,20 @@ static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-built
|
|
12
12
|
static const xmlChar *NOKOGIRI_BUILTIN_URI = (const xmlChar *)"https://www.nokogiri.org/default_ns/ruby/builtins";
|
13
13
|
|
14
14
|
static void
|
15
|
-
xml_xpath_context_deallocate(
|
15
|
+
xml_xpath_context_deallocate(void *data)
|
16
16
|
{
|
17
|
-
|
17
|
+
xmlXPathContextPtr c_context = data;
|
18
|
+
xmlXPathFreeContext(c_context);
|
18
19
|
}
|
19
20
|
|
21
|
+
static const rb_data_type_t xml_xpath_context_type = {
|
22
|
+
.wrap_struct_name = "Nokogiri::XML::XPathContext",
|
23
|
+
.function = {
|
24
|
+
.dfree = xml_xpath_context_deallocate,
|
25
|
+
},
|
26
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
27
|
+
};
|
28
|
+
|
20
29
|
/* find a CSS class in an HTML element's `class` attribute */
|
21
30
|
static const xmlChar *
|
22
31
|
builtin_css_class(const xmlChar *str, const xmlChar *val)
|
@@ -87,7 +96,8 @@ xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
|
|
87
96
|
}
|
88
97
|
|
89
98
|
|
90
|
-
/* xmlXPathFunction to select nodes whose local name matches, for HTML5 CSS queries that should
|
99
|
+
/* xmlXPathFunction to select nodes whose local name matches, for HTML5 CSS queries that should
|
100
|
+
* ignore namespaces */
|
91
101
|
static void
|
92
102
|
xpath_builtin_local_name_is(xmlXPathParserContextPtr ctxt, int nargs)
|
93
103
|
{
|
@@ -100,7 +110,10 @@ xpath_builtin_local_name_is(xmlXPathParserContextPtr ctxt, int nargs)
|
|
100
110
|
CHECK_TYPE(XPATH_STRING);
|
101
111
|
element_name = valuePop(ctxt);
|
102
112
|
|
103
|
-
valuePush(
|
113
|
+
valuePush(
|
114
|
+
ctxt,
|
115
|
+
xmlXPathNewBoolean(xmlStrEqual(ctxt->context->node->name, element_name->stringval))
|
116
|
+
);
|
104
117
|
|
105
118
|
xmlXPathFreeObject(element_name);
|
106
119
|
}
|
@@ -108,44 +121,61 @@ xpath_builtin_local_name_is(xmlXPathParserContextPtr ctxt, int nargs)
|
|
108
121
|
|
109
122
|
/*
|
110
123
|
* call-seq:
|
111
|
-
*
|
124
|
+
* register_ns(prefix, uri) → Nokogiri::XML::XPathContext
|
125
|
+
*
|
126
|
+
* Register the namespace with +prefix+ and +uri+ for use in future queries.
|
112
127
|
*
|
113
|
-
*
|
128
|
+
* [Returns] +self+
|
114
129
|
*/
|
115
130
|
static VALUE
|
116
|
-
rb_xml_xpath_context_register_ns(VALUE
|
131
|
+
rb_xml_xpath_context_register_ns(VALUE rb_context, VALUE prefix, VALUE uri)
|
117
132
|
{
|
118
|
-
xmlXPathContextPtr
|
119
|
-
|
133
|
+
xmlXPathContextPtr c_context;
|
134
|
+
|
135
|
+
TypedData_Get_Struct(
|
136
|
+
rb_context,
|
137
|
+
xmlXPathContext,
|
138
|
+
&xml_xpath_context_type,
|
139
|
+
c_context
|
140
|
+
);
|
120
141
|
|
121
|
-
xmlXPathRegisterNs(
|
142
|
+
xmlXPathRegisterNs(c_context,
|
122
143
|
(const xmlChar *)StringValueCStr(prefix),
|
123
144
|
(const xmlChar *)StringValueCStr(uri)
|
124
145
|
);
|
125
|
-
return
|
146
|
+
return rb_context;
|
126
147
|
}
|
127
148
|
|
128
149
|
/*
|
129
150
|
* call-seq:
|
130
|
-
*
|
151
|
+
* register_variable(name, value) → Nokogiri::XML::XPathContext
|
131
152
|
*
|
132
|
-
* Register the variable +name+ with +value
|
153
|
+
* Register the variable +name+ with +value+ for use in future queries.
|
154
|
+
*
|
155
|
+
* [Returns] +self+
|
133
156
|
*/
|
134
157
|
static VALUE
|
135
|
-
rb_xml_xpath_context_register_variable(VALUE
|
158
|
+
rb_xml_xpath_context_register_variable(VALUE rb_context, VALUE name, VALUE value)
|
136
159
|
{
|
137
|
-
xmlXPathContextPtr
|
160
|
+
xmlXPathContextPtr c_context;
|
138
161
|
xmlXPathObjectPtr xmlValue;
|
139
|
-
|
162
|
+
|
163
|
+
TypedData_Get_Struct(
|
164
|
+
rb_context,
|
165
|
+
xmlXPathContext,
|
166
|
+
&xml_xpath_context_type,
|
167
|
+
c_context
|
168
|
+
);
|
140
169
|
|
141
170
|
xmlValue = xmlXPathNewCString(StringValueCStr(value));
|
142
171
|
|
143
|
-
xmlXPathRegisterVariable(
|
144
|
-
|
145
|
-
|
146
|
-
|
172
|
+
xmlXPathRegisterVariable(
|
173
|
+
c_context,
|
174
|
+
(const xmlChar *)StringValueCStr(name),
|
175
|
+
xmlValue
|
176
|
+
);
|
147
177
|
|
148
|
-
return
|
178
|
+
return rb_context;
|
149
179
|
}
|
150
180
|
|
151
181
|
|
@@ -154,12 +184,12 @@ rb_xml_xpath_context_register_variable(VALUE self, VALUE name, VALUE value)
|
|
154
184
|
* returns Qundef if no conversion was possible.
|
155
185
|
*/
|
156
186
|
static VALUE
|
157
|
-
xpath2ruby(xmlXPathObjectPtr c_xpath_object, xmlXPathContextPtr
|
187
|
+
xpath2ruby(xmlXPathObjectPtr c_xpath_object, xmlXPathContextPtr c_context)
|
158
188
|
{
|
159
189
|
VALUE rb_retval;
|
160
190
|
|
161
|
-
assert(
|
162
|
-
assert(DOC_RUBY_OBJECT_TEST(
|
191
|
+
assert(c_context->doc);
|
192
|
+
assert(DOC_RUBY_OBJECT_TEST(c_context->doc));
|
163
193
|
|
164
194
|
switch (c_xpath_object->type) {
|
165
195
|
case XPATH_STRING:
|
@@ -168,8 +198,10 @@ xpath2ruby(xmlXPathObjectPtr c_xpath_object, xmlXPathContextPtr ctx)
|
|
168
198
|
return rb_retval;
|
169
199
|
|
170
200
|
case XPATH_NODESET:
|
171
|
-
return noko_xml_node_set_wrap(
|
172
|
-
|
201
|
+
return noko_xml_node_set_wrap(
|
202
|
+
c_xpath_object->nodesetval,
|
203
|
+
DOC_RUBY_OBJECT(c_context->doc)
|
204
|
+
);
|
173
205
|
|
174
206
|
case XPATH_NUMBER:
|
175
207
|
return rb_float_new(c_xpath_object->floatval);
|
@@ -184,7 +216,7 @@ xpath2ruby(xmlXPathObjectPtr c_xpath_object, xmlXPathContextPtr ctx)
|
|
184
216
|
|
185
217
|
void
|
186
218
|
Nokogiri_marshal_xpath_funcall_and_return_values(
|
187
|
-
xmlXPathParserContextPtr
|
219
|
+
xmlXPathParserContextPtr ctxt,
|
188
220
|
int argc,
|
189
221
|
VALUE rb_xpath_handler,
|
190
222
|
const char *method_name
|
@@ -196,8 +228,8 @@ Nokogiri_marshal_xpath_funcall_and_return_values(
|
|
196
228
|
xmlNodeSetPtr c_node_set = NULL;
|
197
229
|
xmlXPathObjectPtr c_xpath_object;
|
198
230
|
|
199
|
-
assert(
|
200
|
-
assert(DOC_RUBY_OBJECT_TEST(
|
231
|
+
assert(ctxt->context->doc);
|
232
|
+
assert(DOC_RUBY_OBJECT_TEST(ctxt->context->doc));
|
201
233
|
|
202
234
|
argv = (VALUE *)ruby_xcalloc((size_t)argc, sizeof(VALUE));
|
203
235
|
for (int j = 0 ; j < argc ; ++j) {
|
@@ -205,15 +237,20 @@ Nokogiri_marshal_xpath_funcall_and_return_values(
|
|
205
237
|
}
|
206
238
|
|
207
239
|
for (int j = argc - 1 ; j >= 0 ; --j) {
|
208
|
-
c_xpath_object = valuePop(
|
209
|
-
argv[j] = xpath2ruby(c_xpath_object,
|
240
|
+
c_xpath_object = valuePop(ctxt);
|
241
|
+
argv[j] = xpath2ruby(c_xpath_object, ctxt->context);
|
210
242
|
if (argv[j] == Qundef) {
|
211
243
|
argv[j] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(c_xpath_object));
|
212
244
|
}
|
213
245
|
xmlXPathFreeNodeSetList(c_xpath_object);
|
214
246
|
}
|
215
247
|
|
216
|
-
rb_retval = rb_funcall2(
|
248
|
+
rb_retval = rb_funcall2(
|
249
|
+
rb_xpath_handler,
|
250
|
+
rb_intern((const char *)method_name),
|
251
|
+
argc,
|
252
|
+
argv
|
253
|
+
);
|
217
254
|
|
218
255
|
for (int j = 0 ; j < argc ; ++j) {
|
219
256
|
rb_gc_unregister_address(&argv[j]);
|
@@ -224,31 +261,31 @@ Nokogiri_marshal_xpath_funcall_and_return_values(
|
|
224
261
|
case T_FLOAT:
|
225
262
|
case T_BIGNUM:
|
226
263
|
case T_FIXNUM:
|
227
|
-
xmlXPathReturnNumber(
|
264
|
+
xmlXPathReturnNumber(ctxt, NUM2DBL(rb_retval));
|
228
265
|
break;
|
229
266
|
case T_STRING:
|
230
|
-
xmlXPathReturnString(
|
267
|
+
xmlXPathReturnString(ctxt, xmlCharStrdup(StringValueCStr(rb_retval)));
|
231
268
|
break;
|
232
269
|
case T_TRUE:
|
233
|
-
xmlXPathReturnTrue(
|
270
|
+
xmlXPathReturnTrue(ctxt);
|
234
271
|
break;
|
235
272
|
case T_FALSE:
|
236
|
-
xmlXPathReturnFalse(
|
273
|
+
xmlXPathReturnFalse(ctxt);
|
237
274
|
break;
|
238
275
|
case T_NIL:
|
239
276
|
break;
|
240
277
|
case T_ARRAY: {
|
241
|
-
VALUE construct_args[2] = { DOC_RUBY_OBJECT(
|
278
|
+
VALUE construct_args[2] = { DOC_RUBY_OBJECT(ctxt->context->doc), rb_retval };
|
242
279
|
rb_node_set = rb_class_new_instance(2, construct_args, cNokogiriXmlNodeSet);
|
243
|
-
|
244
|
-
xmlXPathReturnNodeSet(
|
280
|
+
c_node_set = noko_xml_node_set_unwrap(rb_node_set);
|
281
|
+
xmlXPathReturnNodeSet(ctxt, xmlXPathNodeSetMerge(NULL, c_node_set));
|
245
282
|
}
|
246
283
|
break;
|
247
284
|
case T_DATA:
|
248
285
|
if (rb_obj_is_kind_of(rb_retval, cNokogiriXmlNodeSet)) {
|
249
|
-
|
286
|
+
c_node_set = noko_xml_node_set_unwrap(rb_retval);
|
250
287
|
/* Copy the node set, otherwise it will get GC'd. */
|
251
|
-
xmlXPathReturnNodeSet(
|
288
|
+
xmlXPathReturnNodeSet(ctxt, xmlXPathNodeSetMerge(NULL, c_node_set));
|
252
289
|
break;
|
253
290
|
}
|
254
291
|
default:
|
@@ -257,27 +294,39 @@ Nokogiri_marshal_xpath_funcall_and_return_values(
|
|
257
294
|
}
|
258
295
|
|
259
296
|
static void
|
260
|
-
method_caller(xmlXPathParserContextPtr
|
297
|
+
method_caller(xmlXPathParserContextPtr ctxt, int argc)
|
261
298
|
{
|
262
299
|
VALUE rb_xpath_handler = Qnil;
|
263
300
|
const char *method_name = NULL ;
|
264
301
|
|
265
|
-
assert(
|
266
|
-
assert(
|
267
|
-
assert(
|
268
|
-
assert(
|
302
|
+
assert(ctxt);
|
303
|
+
assert(ctxt->context);
|
304
|
+
assert(ctxt->context->userData);
|
305
|
+
assert(ctxt->context->function);
|
269
306
|
|
270
|
-
rb_xpath_handler = (VALUE)(
|
271
|
-
method_name = (const char *)(
|
307
|
+
rb_xpath_handler = (VALUE)(ctxt->context->userData);
|
308
|
+
method_name = (const char *)(ctxt->context->function);
|
272
309
|
|
273
|
-
Nokogiri_marshal_xpath_funcall_and_return_values(
|
310
|
+
Nokogiri_marshal_xpath_funcall_and_return_values(
|
311
|
+
ctxt,
|
312
|
+
argc,
|
313
|
+
rb_xpath_handler,
|
314
|
+
method_name
|
315
|
+
);
|
274
316
|
}
|
275
317
|
|
276
318
|
static xmlXPathFunction
|
277
|
-
handler_lookup(void *
|
319
|
+
handler_lookup(void *data, const xmlChar *c_name, const xmlChar *c_ns_uri)
|
278
320
|
{
|
279
|
-
VALUE
|
280
|
-
if (rb_respond_to(
|
321
|
+
VALUE rb_handler = (VALUE)data;
|
322
|
+
if (rb_respond_to(rb_handler, rb_intern((const char *)c_name))) {
|
323
|
+
if (c_ns_uri == NULL) {
|
324
|
+
NOKO_WARN_DEPRECATION(
|
325
|
+
"A custom XPath or CSS handler function named '%s' is being invoked without a namespace."
|
326
|
+
" Please update your query to reference this function as 'nokogiri:%s'."
|
327
|
+
" Invoking custom handler functions without a namespace is deprecated and support will be removed in a future release of Nokogiri.",
|
328
|
+
c_name, c_name);
|
329
|
+
}
|
281
330
|
return method_caller;
|
282
331
|
}
|
283
332
|
|
@@ -286,9 +335,9 @@ handler_lookup(void *ctx, const xmlChar *c_name, const xmlChar *c_ns_uri)
|
|
286
335
|
|
287
336
|
PRINTFLIKE_DECL(2, 3)
|
288
337
|
static void
|
289
|
-
generic_exception_pusher(void *
|
338
|
+
generic_exception_pusher(void *data, const char *msg, ...)
|
290
339
|
{
|
291
|
-
VALUE rb_errors = (VALUE)
|
340
|
+
VALUE rb_errors = (VALUE)data;
|
292
341
|
VALUE rb_message;
|
293
342
|
VALUE rb_exception;
|
294
343
|
|
@@ -311,21 +360,29 @@ generic_exception_pusher(void *ctx, const char *msg, ...)
|
|
311
360
|
|
312
361
|
/*
|
313
362
|
* call-seq:
|
314
|
-
*
|
363
|
+
* evaluate(search_path, handler = nil) → Object
|
364
|
+
*
|
365
|
+
* Evaluate the +search_path+ query.
|
315
366
|
*
|
316
|
-
*
|
367
|
+
* [Returns] an object of the appropriate type for the query, which could be +NodeSet+, a +String+,
|
368
|
+
* a +Float+, or a boolean.
|
317
369
|
*/
|
318
370
|
static VALUE
|
319
|
-
rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE
|
371
|
+
rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE rb_context)
|
320
372
|
{
|
321
373
|
VALUE search_path, xpath_handler;
|
322
374
|
VALUE retval = Qnil;
|
323
|
-
xmlXPathContextPtr
|
375
|
+
xmlXPathContextPtr c_context;
|
324
376
|
xmlXPathObjectPtr xpath;
|
325
377
|
xmlChar *query;
|
326
378
|
VALUE errors = rb_ary_new();
|
327
379
|
|
328
|
-
|
380
|
+
TypedData_Get_Struct(
|
381
|
+
rb_context,
|
382
|
+
xmlXPathContext,
|
383
|
+
&xml_xpath_context_type,
|
384
|
+
c_context
|
385
|
+
);
|
329
386
|
|
330
387
|
if (rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1) {
|
331
388
|
xpath_handler = Qnil;
|
@@ -335,14 +392,18 @@ rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE self)
|
|
335
392
|
|
336
393
|
if (Qnil != xpath_handler) {
|
337
394
|
/* FIXME: not sure if this is the correct place to shove private data. */
|
338
|
-
|
339
|
-
xmlXPathRegisterFuncLookup(
|
395
|
+
c_context->userData = (void *)xpath_handler;
|
396
|
+
xmlXPathRegisterFuncLookup(
|
397
|
+
c_context,
|
398
|
+
handler_lookup,
|
399
|
+
(void *)xpath_handler
|
400
|
+
);
|
340
401
|
}
|
341
402
|
|
342
403
|
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
343
404
|
xmlSetGenericErrorFunc((void *)errors, generic_exception_pusher);
|
344
405
|
|
345
|
-
xpath = xmlXPathEvalExpression(query,
|
406
|
+
xpath = xmlXPathEvalExpression(query, c_context);
|
346
407
|
|
347
408
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
348
409
|
xmlSetGenericErrorFunc(NULL, NULL);
|
@@ -351,9 +412,9 @@ rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE self)
|
|
351
412
|
rb_exc_raise(rb_ary_entry(errors, 0));
|
352
413
|
}
|
353
414
|
|
354
|
-
retval = xpath2ruby(xpath,
|
415
|
+
retval = xpath2ruby(xpath, c_context);
|
355
416
|
if (retval == Qundef) {
|
356
|
-
retval = noko_xml_node_set_wrap(NULL, DOC_RUBY_OBJECT(
|
417
|
+
retval = noko_xml_node_set_wrap(NULL, DOC_RUBY_OBJECT(c_context->doc));
|
357
418
|
}
|
358
419
|
|
359
420
|
xmlXPathFreeNodeSetList(xpath);
|
@@ -363,43 +424,55 @@ rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE self)
|
|
363
424
|
|
364
425
|
/*
|
365
426
|
* call-seq:
|
366
|
-
*
|
427
|
+
* new(node)
|
367
428
|
*
|
368
|
-
* Create a new XPathContext with +node+ as the
|
429
|
+
* Create a new XPathContext with +node+ as the context node.
|
369
430
|
*/
|
370
431
|
static VALUE
|
371
|
-
rb_xml_xpath_context_new(VALUE klass, VALUE
|
432
|
+
rb_xml_xpath_context_new(VALUE klass, VALUE rb_node)
|
372
433
|
{
|
373
434
|
xmlNodePtr node;
|
374
|
-
xmlXPathContextPtr
|
375
|
-
VALUE
|
435
|
+
xmlXPathContextPtr c_context;
|
436
|
+
VALUE rb_context;
|
376
437
|
|
377
|
-
Noko_Node_Get_Struct(
|
438
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, node);
|
378
439
|
|
379
440
|
#if LIBXML_VERSION < 21000
|
380
441
|
/* deprecated in 40483d0 */
|
381
442
|
xmlXPathInit();
|
382
443
|
#endif
|
383
444
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
xmlXPathRegisterNs(
|
388
|
-
xmlXPathRegisterNs(
|
389
|
-
xmlXPathRegisterFuncNS(
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
445
|
+
c_context = xmlXPathNewContext(node->doc);
|
446
|
+
c_context->node = node;
|
447
|
+
|
448
|
+
xmlXPathRegisterNs(c_context, NOKOGIRI_PREFIX, NOKOGIRI_URI);
|
449
|
+
xmlXPathRegisterNs(c_context, NOKOGIRI_BUILTIN_PREFIX, NOKOGIRI_BUILTIN_URI);
|
450
|
+
xmlXPathRegisterFuncNS(
|
451
|
+
c_context,
|
452
|
+
(const xmlChar *)"css-class",
|
453
|
+
NOKOGIRI_BUILTIN_URI,
|
454
|
+
xpath_builtin_css_class
|
455
|
+
);
|
456
|
+
xmlXPathRegisterFuncNS(
|
457
|
+
c_context,
|
458
|
+
(const xmlChar *)"local-name-is",
|
459
|
+
NOKOGIRI_BUILTIN_URI,
|
460
|
+
xpath_builtin_local_name_is
|
461
|
+
);
|
462
|
+
|
463
|
+
rb_context = TypedData_Wrap_Struct(
|
464
|
+
klass,
|
465
|
+
&xml_xpath_context_type,
|
466
|
+
c_context
|
467
|
+
);
|
468
|
+
return rb_context;
|
396
469
|
}
|
397
470
|
|
398
471
|
void
|
399
472
|
noko_init_xml_xpath_context(void)
|
400
473
|
{
|
401
474
|
/*
|
402
|
-
* XPathContext is the entry point for searching a Document by using XPath.
|
475
|
+
* XPathContext is the entry point for searching a +Document+ by using XPath.
|
403
476
|
*/
|
404
477
|
cNokogiriXmlXpathContext = rb_define_class_under(mNokogiriXml, "XPathContext", rb_cObject);
|
405
478
|
|