nokogiri 1.11.0.rc1-x86-mingw32 → 1.11.1-x86-mingw32
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 +3 -0
- data/LICENSE-DEPENDENCIES.md +1015 -947
- data/README.md +164 -92
- data/ext/nokogiri/depend +476 -357
- data/ext/nokogiri/extconf.rb +467 -326
- data/ext/nokogiri/html_document.c +79 -78
- data/ext/nokogiri/html_sax_parser_context.c +4 -2
- data/ext/nokogiri/html_sax_push_parser.c +14 -8
- data/ext/nokogiri/include/libexslt/exslt.h +102 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +126 -0
- data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
- data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
- data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
- data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
- data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
- data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1241 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
- data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +366 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +945 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +153 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +566 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
- data/ext/nokogiri/include/libxslt/attributes.h +38 -0
- data/ext/nokogiri/include/libxslt/documents.h +93 -0
- data/ext/nokogiri/include/libxslt/extensions.h +262 -0
- data/ext/nokogiri/include/libxslt/extra.h +72 -0
- data/ext/nokogiri/include/libxslt/functions.h +78 -0
- data/ext/nokogiri/include/libxslt/imports.h +75 -0
- data/ext/nokogiri/include/libxslt/keys.h +53 -0
- data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
- data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
- data/ext/nokogiri/include/libxslt/pattern.h +84 -0
- data/ext/nokogiri/include/libxslt/preproc.h +43 -0
- data/ext/nokogiri/include/libxslt/security.h +104 -0
- data/ext/nokogiri/include/libxslt/templates.h +77 -0
- data/ext/nokogiri/include/libxslt/transform.h +207 -0
- data/ext/nokogiri/include/libxslt/variables.h +118 -0
- data/ext/nokogiri/include/libxslt/xslt.h +110 -0
- data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
- data/ext/nokogiri/nokogiri.c +37 -46
- data/ext/nokogiri/nokogiri.h +25 -17
- data/ext/nokogiri/test_global_handlers.c +41 -0
- data/ext/nokogiri/xml_document.c +8 -3
- data/ext/nokogiri/xml_io.c +8 -6
- data/ext/nokogiri/xml_node.c +1 -1
- data/ext/nokogiri/xml_node_set.c +1 -1
- data/ext/nokogiri/xml_reader.c +6 -17
- data/ext/nokogiri/xml_relax_ng.c +29 -11
- data/ext/nokogiri/xml_sax_parser.c +2 -7
- data/ext/nokogiri/xml_sax_parser_context.c +4 -2
- data/ext/nokogiri/xml_sax_push_parser.c +2 -0
- data/ext/nokogiri/xml_schema.c +84 -13
- data/ext/nokogiri/xml_syntax_error.c +23 -0
- data/ext/nokogiri/xml_syntax_error.h +15 -3
- data/ext/nokogiri/xml_xpath_context.c +80 -4
- data/ext/nokogiri/xslt_stylesheet.c +1 -4
- data/lib/nokogiri.rb +20 -3
- data/lib/nokogiri/2.5/nokogiri.so +0 -0
- data/lib/nokogiri/2.6/nokogiri.so +0 -0
- data/lib/nokogiri/2.7/nokogiri.so +0 -0
- data/lib/nokogiri/3.0/nokogiri.so +0 -0
- data/lib/nokogiri/css/parser.rb +62 -62
- data/lib/nokogiri/css/parser.y +2 -2
- data/lib/nokogiri/css/parser_extras.rb +38 -36
- data/lib/nokogiri/css/xpath_visitor.rb +70 -42
- data/lib/nokogiri/html/document.rb +12 -26
- data/lib/nokogiri/version.rb +2 -148
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +182 -0
- data/lib/nokogiri/xml/builder.rb +2 -2
- data/lib/nokogiri/xml/document.rb +17 -7
- data/lib/nokogiri/xml/document_fragment.rb +4 -6
- data/lib/nokogiri/xml/node.rb +562 -238
- data/lib/nokogiri/xml/parse_options.rb +6 -0
- data/lib/nokogiri/xml/relax_ng.rb +6 -2
- data/lib/nokogiri/xml/schema.rb +12 -4
- data/lib/nokogiri/xml/searchable.rb +24 -16
- metadata +149 -130
- data/lib/nokogiri/2.4/nokogiri.so +0 -0
@@ -1,8 +1,5 @@
|
|
1
1
|
#include <xml_sax_parser.h>
|
2
2
|
|
3
|
-
int vasprintf (char **strp, const char *fmt, va_list ap);
|
4
|
-
void vasprintf_free (void *p);
|
5
|
-
|
6
3
|
static ID id_start_document, id_end_document, id_start_element, id_end_element;
|
7
4
|
static ID id_start_element_namespace, id_end_element_namespace;
|
8
5
|
static ID id_comment, id_characters, id_xmldecl, id_error, id_warning;
|
@@ -206,7 +203,7 @@ static void warning_func(void * ctx, const char *msg, ...)
|
|
206
203
|
va_end(args);
|
207
204
|
|
208
205
|
ruby_message = NOKOGIRI_STR_NEW2(message);
|
209
|
-
|
206
|
+
free(message);
|
210
207
|
rb_funcall(doc, id_warning, 1, ruby_message);
|
211
208
|
}
|
212
209
|
|
@@ -223,7 +220,7 @@ static void error_func(void * ctx, const char *msg, ...)
|
|
223
220
|
va_end(args);
|
224
221
|
|
225
222
|
ruby_message = NOKOGIRI_STR_NEW2(message);
|
226
|
-
|
223
|
+
free(message);
|
227
224
|
rb_funcall(doc, id_error, 1, ruby_message);
|
228
225
|
}
|
229
226
|
|
@@ -262,8 +259,6 @@ static VALUE allocate(VALUE klass)
|
|
262
259
|
{
|
263
260
|
xmlSAXHandlerPtr handler = calloc((size_t)1, sizeof(xmlSAXHandler));
|
264
261
|
|
265
|
-
xmlSetStructuredErrorFunc(NULL, NULL);
|
266
|
-
|
267
262
|
handler->startDocument = start_document;
|
268
263
|
handler->endDocument = end_document;
|
269
264
|
handler->startElement = start_element;
|
@@ -4,13 +4,13 @@ VALUE cNokogiriXmlSaxParserContext ;
|
|
4
4
|
|
5
5
|
static void deallocate(xmlParserCtxtPtr ctxt)
|
6
6
|
{
|
7
|
-
NOKOGIRI_DEBUG_START(
|
7
|
+
NOKOGIRI_DEBUG_START(ctxt);
|
8
8
|
|
9
9
|
ctxt->sax = NULL;
|
10
10
|
|
11
11
|
xmlFreeParserCtxt(ctxt);
|
12
12
|
|
13
|
-
NOKOGIRI_DEBUG_END(
|
13
|
+
NOKOGIRI_DEBUG_END(ctxt);
|
14
14
|
}
|
15
15
|
|
16
16
|
/*
|
@@ -120,6 +120,8 @@ parse_with(VALUE self, VALUE sax_handler)
|
|
120
120
|
ctxt->sax = sax;
|
121
121
|
ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);
|
122
122
|
|
123
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
124
|
+
|
123
125
|
rb_ensure(parse_doc, (VALUE)ctxt, parse_doc_finalize, (VALUE)ctxt);
|
124
126
|
|
125
127
|
return Qnil;
|
@@ -35,6 +35,8 @@ static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
|
|
35
35
|
size = (int)RSTRING_LEN(_chunk);
|
36
36
|
}
|
37
37
|
|
38
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
39
|
+
|
38
40
|
if (xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
|
39
41
|
if (!(ctx->options & XML_PARSE_RECOVER)) {
|
40
42
|
xmlErrorPtr e = xmlCtxtGetLastError(ctx);
|
data/ext/nokogiri/xml_schema.c
CHANGED
@@ -93,15 +93,27 @@ static VALUE validate_file(VALUE self, VALUE rb_filename)
|
|
93
93
|
*
|
94
94
|
* Create a new Schema from the contents of +string+
|
95
95
|
*/
|
96
|
-
static VALUE read_memory(VALUE
|
96
|
+
static VALUE read_memory(int argc, VALUE *argv, VALUE klass)
|
97
97
|
{
|
98
|
+
VALUE content;
|
99
|
+
VALUE parse_options;
|
100
|
+
int parse_options_int;
|
101
|
+
xmlSchemaParserCtxtPtr ctx;
|
98
102
|
xmlSchemaPtr schema;
|
99
|
-
|
100
|
-
(const char *)StringValuePtr(content),
|
101
|
-
(int)RSTRING_LEN(content)
|
102
|
-
);
|
103
|
+
VALUE errors;
|
103
104
|
VALUE rb_schema;
|
104
|
-
|
105
|
+
int scanned_args = 0;
|
106
|
+
xmlExternalEntityLoader old_loader = 0;
|
107
|
+
|
108
|
+
scanned_args = rb_scan_args(argc, argv, "11", &content, &parse_options);
|
109
|
+
if (scanned_args == 1) {
|
110
|
+
parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
111
|
+
}
|
112
|
+
parse_options_int = (int)NUM2INT(rb_funcall(parse_options, rb_intern("to_i"), 0));
|
113
|
+
|
114
|
+
ctx = xmlSchemaNewMemParserCtxt((const char *)StringValuePtr(content), (int)RSTRING_LEN(content));
|
115
|
+
|
116
|
+
errors = rb_ary_new();
|
105
117
|
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
106
118
|
|
107
119
|
#ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
|
@@ -109,10 +121,19 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
109
121
|
ctx,
|
110
122
|
Nokogiri_error_array_pusher,
|
111
123
|
(void *)errors
|
112
|
-
|
124
|
+
);
|
113
125
|
#endif
|
114
126
|
|
115
|
-
|
127
|
+
if (parse_options_int & XML_PARSE_NONET) {
|
128
|
+
old_loader = xmlGetExternalEntityLoader();
|
129
|
+
xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
|
130
|
+
}
|
131
|
+
|
132
|
+
schema = xmlSchemaParse(ctx);
|
133
|
+
|
134
|
+
if (old_loader) {
|
135
|
+
xmlSetExternalEntityLoader(old_loader);
|
136
|
+
}
|
116
137
|
|
117
138
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
118
139
|
xmlSchemaFreeParserCtxt(ctx);
|
@@ -129,28 +150,68 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
129
150
|
|
130
151
|
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
131
152
|
rb_iv_set(rb_schema, "@errors", errors);
|
153
|
+
rb_iv_set(rb_schema, "@parse_options", parse_options);
|
132
154
|
|
133
155
|
return rb_schema;
|
134
156
|
}
|
135
157
|
|
158
|
+
/* Schema creation will remove and deallocate "blank" nodes.
|
159
|
+
* If those blank nodes have been exposed to Ruby, they could get freed
|
160
|
+
* out from under the VALUE pointer. This function checks to see if any of
|
161
|
+
* those nodes have been exposed to Ruby, and if so we should raise an exception.
|
162
|
+
*/
|
163
|
+
static int has_blank_nodes_p(VALUE cache)
|
164
|
+
{
|
165
|
+
long i;
|
166
|
+
|
167
|
+
if (NIL_P(cache)) {
|
168
|
+
return 0;
|
169
|
+
}
|
170
|
+
|
171
|
+
for (i = 0; i < RARRAY_LEN(cache); i++) {
|
172
|
+
xmlNodePtr node;
|
173
|
+
VALUE element = rb_ary_entry(cache, i);
|
174
|
+
Data_Get_Struct(element, xmlNode, node);
|
175
|
+
if (xmlIsBlankNode(node)) {
|
176
|
+
return 1;
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
180
|
+
return 0;
|
181
|
+
}
|
182
|
+
|
136
183
|
/*
|
137
184
|
* call-seq:
|
138
185
|
* from_document(doc)
|
139
186
|
*
|
140
187
|
* Create a new Schema from the Nokogiri::XML::Document +doc+
|
141
188
|
*/
|
142
|
-
static VALUE from_document(VALUE
|
189
|
+
static VALUE from_document(int argc, VALUE *argv, VALUE klass)
|
143
190
|
{
|
191
|
+
VALUE document;
|
192
|
+
VALUE parse_options;
|
193
|
+
int parse_options_int;
|
144
194
|
xmlDocPtr doc;
|
145
195
|
xmlSchemaParserCtxtPtr ctx;
|
146
196
|
xmlSchemaPtr schema;
|
147
197
|
VALUE errors;
|
148
198
|
VALUE rb_schema;
|
199
|
+
int scanned_args = 0;
|
200
|
+
xmlExternalEntityLoader old_loader = 0;
|
201
|
+
|
202
|
+
scanned_args = rb_scan_args(argc, argv, "11", &document, &parse_options);
|
149
203
|
|
150
204
|
Data_Get_Struct(document, xmlDoc, doc);
|
205
|
+
doc = doc->doc; /* In case someone passes us a node. ugh. */
|
151
206
|
|
152
|
-
|
153
|
-
|
207
|
+
if (scanned_args == 1) {
|
208
|
+
parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
209
|
+
}
|
210
|
+
parse_options_int = (int)NUM2INT(rb_funcall(parse_options, rb_intern("to_i"), 0));
|
211
|
+
|
212
|
+
if (has_blank_nodes_p(DOC_NODE_CACHE(doc))) {
|
213
|
+
rb_raise(rb_eArgError, "Creating a schema from a document that has blank nodes exposed to Ruby is dangerous");
|
214
|
+
}
|
154
215
|
|
155
216
|
ctx = xmlSchemaNewDocParserCtxt(doc);
|
156
217
|
|
@@ -165,8 +226,17 @@ static VALUE from_document(VALUE klass, VALUE document)
|
|
165
226
|
);
|
166
227
|
#endif
|
167
228
|
|
229
|
+
if (parse_options_int & XML_PARSE_NONET) {
|
230
|
+
old_loader = xmlGetExternalEntityLoader();
|
231
|
+
xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
|
232
|
+
}
|
233
|
+
|
168
234
|
schema = xmlSchemaParse(ctx);
|
169
235
|
|
236
|
+
if (old_loader) {
|
237
|
+
xmlSetExternalEntityLoader(old_loader);
|
238
|
+
}
|
239
|
+
|
170
240
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
171
241
|
xmlSchemaFreeParserCtxt(ctx);
|
172
242
|
|
@@ -182,6 +252,7 @@ static VALUE from_document(VALUE klass, VALUE document)
|
|
182
252
|
|
183
253
|
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
184
254
|
rb_iv_set(rb_schema, "@errors", errors);
|
255
|
+
rb_iv_set(rb_schema, "@parse_options", parse_options);
|
185
256
|
|
186
257
|
return rb_schema;
|
187
258
|
|
@@ -197,8 +268,8 @@ void init_xml_schema()
|
|
197
268
|
|
198
269
|
cNokogiriXmlSchema = klass;
|
199
270
|
|
200
|
-
rb_define_singleton_method(klass, "read_memory", read_memory, 1);
|
201
|
-
rb_define_singleton_method(klass, "from_document", from_document, 1);
|
271
|
+
rb_define_singleton_method(klass, "read_memory", read_memory, -1);
|
272
|
+
rb_define_singleton_method(klass, "from_document", from_document, -1);
|
202
273
|
|
203
274
|
rb_define_private_method(klass, "validate_document", validate_document, 1);
|
204
275
|
rb_define_private_method(klass, "validate_file", validate_file, 1);
|
@@ -1,5 +1,28 @@
|
|
1
1
|
#include <xml_syntax_error.h>
|
2
2
|
|
3
|
+
void
|
4
|
+
Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state)
|
5
|
+
{
|
6
|
+
/* this method is tightly coupled to the implementation of xmlSetStructuredErrorFunc */
|
7
|
+
handler_state->user_data = xmlStructuredErrorContext;
|
8
|
+
handler_state->handler = xmlStructuredError;
|
9
|
+
}
|
10
|
+
|
11
|
+
void
|
12
|
+
Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state,
|
13
|
+
void *user_data,
|
14
|
+
xmlStructuredErrorFunc handler)
|
15
|
+
{
|
16
|
+
Nokogiri_structured_error_func_save(handler_state);
|
17
|
+
xmlSetStructuredErrorFunc(user_data, handler);
|
18
|
+
}
|
19
|
+
|
20
|
+
void
|
21
|
+
Nokogiri_structured_error_func_restore(libxmlStructuredErrorHandlerState *handler_state)
|
22
|
+
{
|
23
|
+
xmlSetStructuredErrorFunc(handler_state->user_data, handler_state->handler);
|
24
|
+
}
|
25
|
+
|
3
26
|
void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error)
|
4
27
|
{
|
5
28
|
VALUE list = (VALUE)ctx;
|
@@ -3,11 +3,23 @@
|
|
3
3
|
|
4
4
|
#include <nokogiri.h>
|
5
5
|
|
6
|
+
typedef struct _libxmlStructuredErrorHandlerState {
|
7
|
+
void *user_data;
|
8
|
+
xmlStructuredErrorFunc handler;
|
9
|
+
} libxmlStructuredErrorHandlerState ;
|
10
|
+
|
6
11
|
void init_xml_syntax_error();
|
12
|
+
|
13
|
+
void Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state);
|
14
|
+
void Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state,
|
15
|
+
void *user_data,
|
16
|
+
xmlStructuredErrorFunc handler);
|
17
|
+
void Nokogiri_structured_error_func_restore(libxmlStructuredErrorHandlerState *handler_state);
|
18
|
+
|
7
19
|
VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error);
|
8
|
-
void Nokogiri_error_array_pusher(void *
|
9
|
-
NORETURN(void Nokogiri_error_raise(void *
|
20
|
+
void Nokogiri_error_array_pusher(void *ctx, xmlErrorPtr error);
|
21
|
+
NORETURN(void Nokogiri_error_raise(void *ctx, xmlErrorPtr error));
|
10
22
|
|
11
23
|
extern VALUE cNokogiriXmlSyntaxError;
|
12
|
-
#endif
|
13
24
|
|
25
|
+
#endif /* NOKOGIRI_XML_SYNTAX_ERROR */
|
@@ -1,6 +1,11 @@
|
|
1
1
|
#include <xml_xpath_context.h>
|
2
2
|
|
3
|
-
|
3
|
+
/*
|
4
|
+
* these constants have matching declarations in
|
5
|
+
* ext/java/nokogiri/internals/NokogiriNamespaceContext.java
|
6
|
+
*/
|
7
|
+
static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-builtin";
|
8
|
+
static const xmlChar *NOKOGIRI_BUILTIN_URI = (const xmlChar *)"https://www.nokogiri.org/default_ns/ruby/builtins";
|
4
9
|
|
5
10
|
static void deallocate(xmlXPathContextPtr ctx)
|
6
11
|
{
|
@@ -9,6 +14,73 @@ static void deallocate(xmlXPathContextPtr ctx)
|
|
9
14
|
NOKOGIRI_DEBUG_END(ctx);
|
10
15
|
}
|
11
16
|
|
17
|
+
/* find a CSS class in an HTML element's `class` attribute */
|
18
|
+
const xmlChar* builtin_css_class(const xmlChar* str, const xmlChar *val)
|
19
|
+
{
|
20
|
+
int val_len;
|
21
|
+
|
22
|
+
if (str == NULL) { return(NULL); }
|
23
|
+
if (val == NULL) { return(NULL); }
|
24
|
+
|
25
|
+
val_len = xmlStrlen(val);
|
26
|
+
if (val_len == 0) { return(str); }
|
27
|
+
|
28
|
+
while (*str != 0) {
|
29
|
+
if ((*str == *val) && !xmlStrncmp(str, val, val_len)) {
|
30
|
+
const xmlChar* next_byte = str + val_len;
|
31
|
+
|
32
|
+
/* only match if the next byte is whitespace or end of string */
|
33
|
+
if ((*next_byte == 0) || (IS_BLANK_CH(*next_byte))) {
|
34
|
+
return((const xmlChar*)str);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
/* advance str to whitespace */
|
39
|
+
while ((*str != 0) && !IS_BLANK_CH(*str)) {
|
40
|
+
str++;
|
41
|
+
}
|
42
|
+
|
43
|
+
/* advance str to start of next word or end of string */
|
44
|
+
while ((*str != 0) && IS_BLANK_CH(*str)) {
|
45
|
+
str++;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
return(NULL);
|
50
|
+
}
|
51
|
+
|
52
|
+
/* xmlXPathFunction to wrap builtin_css_class() */
|
53
|
+
static void xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
|
54
|
+
{
|
55
|
+
xmlXPathObjectPtr hay, needle;
|
56
|
+
|
57
|
+
CHECK_ARITY(2);
|
58
|
+
|
59
|
+
CAST_TO_STRING;
|
60
|
+
needle = valuePop(ctxt);
|
61
|
+
if ((needle == NULL) || (needle->type != XPATH_STRING)) {
|
62
|
+
xmlXPathFreeObject(needle);
|
63
|
+
XP_ERROR(XPATH_INVALID_TYPE);
|
64
|
+
}
|
65
|
+
|
66
|
+
CAST_TO_STRING;
|
67
|
+
hay = valuePop(ctxt);
|
68
|
+
if ((hay == NULL) || (hay->type != XPATH_STRING)) {
|
69
|
+
xmlXPathFreeObject(hay);
|
70
|
+
xmlXPathFreeObject(needle);
|
71
|
+
XP_ERROR(XPATH_INVALID_TYPE);
|
72
|
+
}
|
73
|
+
|
74
|
+
if (builtin_css_class(hay->stringval, needle->stringval)) {
|
75
|
+
valuePush(ctxt, xmlXPathNewBoolean(1));
|
76
|
+
} else {
|
77
|
+
valuePush(ctxt, xmlXPathNewBoolean(0));
|
78
|
+
}
|
79
|
+
|
80
|
+
xmlXPathFreeObject(hay);
|
81
|
+
xmlXPathFreeObject(needle);
|
82
|
+
}
|
83
|
+
|
12
84
|
/*
|
13
85
|
* call-seq:
|
14
86
|
* register_ns(prefix, uri)
|
@@ -263,14 +335,18 @@ static VALUE new(VALUE klass, VALUE nodeobj)
|
|
263
335
|
xmlXPathContextPtr ctx;
|
264
336
|
VALUE self;
|
265
337
|
|
266
|
-
xmlXPathInit();
|
267
|
-
|
268
338
|
Data_Get_Struct(nodeobj, xmlNode, node);
|
269
339
|
|
340
|
+
xmlXPathInit();
|
341
|
+
|
270
342
|
ctx = xmlXPathNewContext(node->doc);
|
271
343
|
ctx->node = node;
|
344
|
+
|
345
|
+
xmlXPathRegisterNs(ctx, NOKOGIRI_BUILTIN_PREFIX, NOKOGIRI_BUILTIN_URI);
|
346
|
+
xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"css-class", NOKOGIRI_BUILTIN_URI,
|
347
|
+
xpath_builtin_css_class);
|
348
|
+
|
272
349
|
self = Data_Wrap_Struct(klass, 0, deallocate, ctx);
|
273
|
-
/*rb_iv_set(self, "@xpath_handler", Qnil); */
|
274
350
|
return self;
|
275
351
|
}
|
276
352
|
|
@@ -7,9 +7,6 @@
|
|
7
7
|
|
8
8
|
VALUE xslt;
|
9
9
|
|
10
|
-
int vasprintf (char **strp, const char *fmt, va_list ap);
|
11
|
-
void vasprintf_free (void *p);
|
12
|
-
|
13
10
|
static void mark(nokogiriXsltStylesheetTuple *wrapper)
|
14
11
|
{
|
15
12
|
rb_gc_mark(wrapper->func_instances);
|
@@ -37,7 +34,7 @@ static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
|
|
37
34
|
|
38
35
|
rb_str_cat2((VALUE)ctx, message);
|
39
36
|
|
40
|
-
|
37
|
+
free(message);
|
41
38
|
}
|
42
39
|
|
43
40
|
VALUE Nokogiri_wrap_xslt_stylesheet(xsltStylesheetPtr ss)
|
data/lib/nokogiri.rb
CHANGED
@@ -11,7 +11,24 @@ end
|
|
11
11
|
begin
|
12
12
|
RUBY_VERSION =~ /(\d+\.\d+)/
|
13
13
|
require "nokogiri/#{$1}/nokogiri"
|
14
|
-
rescue LoadError
|
14
|
+
rescue LoadError => e
|
15
|
+
if e.message =~ /GLIBC/
|
16
|
+
warn <<~EOM
|
17
|
+
|
18
|
+
ERROR: It looks like you're trying to use Nokogiri as a precompiled native gem on a system with glibc < 2.17:
|
19
|
+
|
20
|
+
#{e.message}
|
21
|
+
|
22
|
+
If that's the case, then please install Nokogiri via the `ruby` platform gem:
|
23
|
+
gem install nokogiri --platform=ruby
|
24
|
+
or:
|
25
|
+
bundle config set force_ruby_platform true
|
26
|
+
|
27
|
+
Please visit https://nokogiri.org/tutorials/installing_nokogiri.html for more help.
|
28
|
+
|
29
|
+
EOM
|
30
|
+
raise e
|
31
|
+
end
|
15
32
|
require 'nokogiri/nokogiri'
|
16
33
|
end
|
17
34
|
require 'nokogiri/version'
|
@@ -37,7 +54,7 @@ require 'nokogiri/html/builder'
|
|
37
54
|
#
|
38
55
|
# # Get a Nokogiri::HTML:Document for the page we’re interested in...
|
39
56
|
#
|
40
|
-
# doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
|
57
|
+
# doc = Nokogiri::HTML(URI.open('http://www.google.com/search?q=tenderlove'))
|
41
58
|
#
|
42
59
|
# # Do funky things with it using Nokogiri::XML::Node methods...
|
43
60
|
#
|
@@ -113,7 +130,7 @@ module Nokogiri
|
|
113
130
|
end
|
114
131
|
|
115
132
|
###
|
116
|
-
#
|
133
|
+
# Parse a document contained in +args+. Nokogiri will try to guess what
|
117
134
|
# type of document you are attempting to parse. For more information, see
|
118
135
|
# Nokogiri.parse
|
119
136
|
#
|