nokogiri 1.11.1 → 1.12.0.rc1
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/LICENSE-DEPENDENCIES.md +232 -11
- data/LICENSE.md +1 -1
- data/README.md +27 -21
- data/dependencies.yml +12 -12
- data/ext/nokogiri/depend +35 -474
- data/ext/nokogiri/extconf.rb +391 -243
- data/ext/nokogiri/gumbo.c +611 -0
- data/ext/nokogiri/{html_document.c → html4_document.c} +18 -23
- data/ext/nokogiri/html4_element_description.c +294 -0
- data/ext/nokogiri/html4_entity_lookup.c +37 -0
- data/ext/nokogiri/html4_sax_parser_context.c +119 -0
- data/ext/nokogiri/{html_sax_push_parser.c → html4_sax_push_parser.c} +29 -27
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +206 -66
- data/ext/nokogiri/nokogiri.h +166 -76
- data/ext/nokogiri/test_global_handlers.c +3 -4
- data/ext/nokogiri/xml_attr.c +15 -15
- data/ext/nokogiri/xml_attribute_decl.c +18 -18
- data/ext/nokogiri/xml_cdata.c +13 -18
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +258 -200
- data/ext/nokogiri/xml_document_fragment.c +13 -15
- data/ext/nokogiri/xml_dtd.c +54 -48
- data/ext/nokogiri/xml_element_content.c +31 -26
- data/ext/nokogiri/xml_element_decl.c +22 -22
- data/ext/nokogiri/xml_encoding_handler.c +28 -17
- data/ext/nokogiri/xml_entity_decl.c +32 -30
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +58 -49
- data/ext/nokogiri/xml_node.c +473 -414
- data/ext/nokogiri/xml_node_set.c +174 -162
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +193 -157
- data/ext/nokogiri/xml_relax_ng.c +29 -23
- data/ext/nokogiri/xml_sax_parser.c +111 -106
- data/ext/nokogiri/xml_sax_parser_context.c +102 -85
- data/ext/nokogiri/xml_sax_push_parser.c +34 -27
- data/ext/nokogiri/xml_schema.c +49 -41
- data/ext/nokogiri/xml_syntax_error.c +21 -23
- data/ext/nokogiri/xml_text.c +13 -17
- data/ext/nokogiri/xml_xpath_context.c +86 -77
- data/ext/nokogiri/xslt_stylesheet.c +157 -156
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +101 -0
- data/gumbo-parser/THANKS +27 -0
- data/gumbo-parser/src/Makefile +17 -0
- data/gumbo-parser/src/README.md +41 -0
- data/gumbo-parser/src/ascii.c +75 -0
- data/gumbo-parser/src/ascii.h +115 -0
- data/gumbo-parser/src/attribute.c +42 -0
- data/gumbo-parser/src/attribute.h +17 -0
- data/gumbo-parser/src/char_ref.c +22225 -0
- data/gumbo-parser/src/char_ref.h +29 -0
- data/gumbo-parser/src/char_ref.rl +2154 -0
- data/gumbo-parser/src/error.c +626 -0
- data/gumbo-parser/src/error.h +148 -0
- data/gumbo-parser/src/foreign_attrs.c +104 -0
- data/gumbo-parser/src/foreign_attrs.gperf +27 -0
- data/gumbo-parser/src/gumbo.h +943 -0
- data/gumbo-parser/src/insertion_mode.h +33 -0
- data/gumbo-parser/src/macros.h +91 -0
- data/gumbo-parser/src/parser.c +4886 -0
- data/gumbo-parser/src/parser.h +41 -0
- data/gumbo-parser/src/replacement.h +33 -0
- data/gumbo-parser/src/string_buffer.c +103 -0
- data/gumbo-parser/src/string_buffer.h +68 -0
- data/gumbo-parser/src/string_piece.c +48 -0
- data/gumbo-parser/src/svg_attrs.c +174 -0
- data/gumbo-parser/src/svg_attrs.gperf +77 -0
- data/gumbo-parser/src/svg_tags.c +137 -0
- data/gumbo-parser/src/svg_tags.gperf +55 -0
- data/gumbo-parser/src/tag.c +222 -0
- data/gumbo-parser/src/tag_lookup.c +382 -0
- data/gumbo-parser/src/tag_lookup.gperf +169 -0
- data/gumbo-parser/src/tag_lookup.h +13 -0
- data/gumbo-parser/src/token_buffer.c +79 -0
- data/gumbo-parser/src/token_buffer.h +71 -0
- data/gumbo-parser/src/token_type.h +17 -0
- data/gumbo-parser/src/tokenizer.c +3463 -0
- data/gumbo-parser/src/tokenizer.h +112 -0
- data/gumbo-parser/src/tokenizer_states.h +339 -0
- data/gumbo-parser/src/utf8.c +245 -0
- data/gumbo-parser/src/utf8.h +164 -0
- data/gumbo-parser/src/util.c +68 -0
- data/gumbo-parser/src/util.h +30 -0
- data/gumbo-parser/src/vector.c +111 -0
- data/gumbo-parser/src/vector.h +45 -0
- data/lib/nokogiri.rb +31 -50
- data/lib/nokogiri/css.rb +14 -14
- data/lib/nokogiri/css/parser.rb +2 -2
- data/lib/nokogiri/css/parser.y +1 -1
- data/lib/nokogiri/css/syntax_error.rb +1 -1
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/gumbo.rb +14 -0
- data/lib/nokogiri/html.rb +31 -27
- data/lib/nokogiri/html4.rb +40 -0
- data/lib/nokogiri/{html → html4}/builder.rb +2 -2
- data/lib/nokogiri/{html → html4}/document.rb +4 -4
- data/lib/nokogiri/{html → html4}/document_fragment.rb +17 -17
- data/lib/nokogiri/{html → html4}/element_description.rb +1 -1
- data/lib/nokogiri/{html → html4}/element_description_defaults.rb +1 -1
- data/lib/nokogiri/{html → html4}/entity_lookup.rb +1 -1
- data/lib/nokogiri/{html → html4}/sax/parser.rb +11 -14
- data/lib/nokogiri/html4/sax/parser_context.rb +19 -0
- data/lib/nokogiri/{html → html4}/sax/push_parser.rb +5 -5
- data/lib/nokogiri/html5.rb +473 -0
- data/lib/nokogiri/html5/document.rb +74 -0
- data/lib/nokogiri/html5/document_fragment.rb +80 -0
- data/lib/nokogiri/html5/node.rb +93 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +42 -9
- data/lib/nokogiri/xml.rb +35 -36
- data/lib/nokogiri/xml/document.rb +74 -28
- data/lib/nokogiri/xml/node.rb +45 -47
- data/lib/nokogiri/xml/parse_options.rb +2 -0
- data/lib/nokogiri/xml/pp.rb +2 -2
- data/lib/nokogiri/xml/reader.rb +2 -9
- data/lib/nokogiri/xml/sax.rb +4 -4
- data/lib/nokogiri/xml/sax/document.rb +24 -30
- data/lib/nokogiri/xml/xpath.rb +3 -5
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- data/lib/nokogiri/xslt.rb +16 -16
- data/lib/nokogiri/xslt/stylesheet.rb +1 -1
- data/patches/libxml2/{0002-Remove-script-macro-support.patch → 0001-Remove-script-macro-support.patch} +0 -0
- data/patches/libxml2/{0003-Update-entities-to-remove-handling-of-ssi.patch → 0002-Update-entities-to-remove-handling-of-ssi.patch} +0 -0
- data/patches/libxml2/{0004-libxml2.la-is-in-top_builddir.patch → 0003-libxml2.la-is-in-top_builddir.patch} +1 -1
- data/patches/libxml2/{0008-use-glibc-strlen.patch → 0004-use-glibc-strlen.patch} +0 -0
- data/patches/libxml2/{0009-avoid-isnan-isinf.patch → 0005-avoid-isnan-isinf.patch} +4 -4
- data/patches/libxml2/0006-update-automake-files-for-arm64.patch +2511 -0
- data/patches/libxml2/0007-Fix-XPath-recursion-limit.patch +31 -0
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2511 -0
- data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +19 -0
- data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
- metadata +117 -109
- data/ext/nokogiri/html_document.h +0 -10
- data/ext/nokogiri/html_element_description.c +0 -279
- data/ext/nokogiri/html_element_description.h +0 -10
- data/ext/nokogiri/html_entity_lookup.c +0 -32
- data/ext/nokogiri/html_entity_lookup.h +0 -8
- data/ext/nokogiri/html_sax_parser_context.c +0 -118
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_attr.h +0 -9
- data/ext/nokogiri/xml_attribute_decl.h +0 -9
- data/ext/nokogiri/xml_cdata.h +0 -9
- data/ext/nokogiri/xml_comment.h +0 -9
- data/ext/nokogiri/xml_document.h +0 -23
- data/ext/nokogiri/xml_document_fragment.h +0 -10
- data/ext/nokogiri/xml_dtd.h +0 -10
- data/ext/nokogiri/xml_element_content.h +0 -10
- data/ext/nokogiri/xml_element_decl.h +0 -9
- data/ext/nokogiri/xml_encoding_handler.h +0 -8
- data/ext/nokogiri/xml_entity_decl.h +0 -10
- data/ext/nokogiri/xml_entity_reference.h +0 -9
- data/ext/nokogiri/xml_io.c +0 -63
- data/ext/nokogiri/xml_io.h +0 -11
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/xml_namespace.h +0 -14
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -12
- data/ext/nokogiri/xml_processing_instruction.h +0 -9
- data/ext/nokogiri/xml_reader.h +0 -10
- data/ext/nokogiri/xml_relax_ng.h +0 -9
- data/ext/nokogiri/xml_sax_parser.h +0 -39
- data/ext/nokogiri/xml_sax_parser_context.h +0 -10
- data/ext/nokogiri/xml_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_schema.h +0 -9
- data/ext/nokogiri/xml_syntax_error.h +0 -25
- data/ext/nokogiri/xml_text.h +0 -9
- data/ext/nokogiri/xml_xpath_context.h +0 -10
- data/ext/nokogiri/xslt_stylesheet.h +0 -14
- data/lib/nokogiri/html/sax/parser_context.rb +0 -17
- data/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch +0 -78
- data/patches/libxml2/0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch +0 -32
- data/patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch +0 -73
- data/patches/libxml2/0007-use-new-htmlParseLookupCommentEnd-to-find-comment-en.patch +0 -103
- data/ports/archives/libxml2-2.9.10.tar.gz +0 -0
@@ -1,4 +1,6 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlSyntaxError;
|
2
4
|
|
3
5
|
void
|
4
6
|
Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state)
|
@@ -10,8 +12,8 @@ Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_s
|
|
10
12
|
|
11
13
|
void
|
12
14
|
Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state,
|
13
|
-
|
14
|
-
|
15
|
+
void *user_data,
|
16
|
+
xmlStructuredErrorFunc handler)
|
15
17
|
{
|
16
18
|
Nokogiri_structured_error_func_save(handler_state);
|
17
19
|
xmlSetStructuredErrorFunc(user_data, handler);
|
@@ -23,39 +25,40 @@ Nokogiri_structured_error_func_restore(libxmlStructuredErrorHandlerState *handle
|
|
23
25
|
xmlSetStructuredErrorFunc(handler_state->user_data, handler_state->handler);
|
24
26
|
}
|
25
27
|
|
26
|
-
void
|
28
|
+
void
|
29
|
+
Nokogiri_error_array_pusher(void *ctx, xmlErrorPtr error)
|
27
30
|
{
|
28
31
|
VALUE list = (VALUE)ctx;
|
29
32
|
Check_Type(list, T_ARRAY);
|
30
33
|
rb_ary_push(list, Nokogiri_wrap_xml_syntax_error(error));
|
31
34
|
}
|
32
35
|
|
33
|
-
void
|
36
|
+
void
|
37
|
+
Nokogiri_error_raise(void *ctx, xmlErrorPtr error)
|
34
38
|
{
|
35
39
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
36
40
|
}
|
37
41
|
|
38
|
-
VALUE
|
42
|
+
VALUE
|
43
|
+
Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error)
|
39
44
|
{
|
40
45
|
VALUE msg, e, klass;
|
41
46
|
|
42
47
|
klass = cNokogiriXmlSyntaxError;
|
43
48
|
|
44
49
|
if (error && error->domain == XML_FROM_XPATH) {
|
45
|
-
|
46
|
-
klass = rb_const_get(xpath, rb_intern("SyntaxError"));
|
50
|
+
klass = cNokogiriXmlXpathSyntaxError;
|
47
51
|
}
|
48
52
|
|
49
53
|
msg = (error && error->message) ? NOKOGIRI_STR_NEW2(error->message) : Qnil;
|
50
54
|
|
51
55
|
e = rb_class_new_instance(
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
1,
|
57
|
+
&msg,
|
58
|
+
klass
|
59
|
+
);
|
56
60
|
|
57
|
-
if (error)
|
58
|
-
{
|
61
|
+
if (error) {
|
59
62
|
rb_iv_set(e, "@domain", INT2NUM(error->domain));
|
60
63
|
rb_iv_set(e, "@code", INT2NUM(error->code));
|
61
64
|
rb_iv_set(e, "@level", INT2NUM((short)error->level));
|
@@ -71,17 +74,12 @@ VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error)
|
|
71
74
|
return e;
|
72
75
|
}
|
73
76
|
|
74
|
-
|
75
|
-
|
77
|
+
void
|
78
|
+
noko_init_xml_syntax_error()
|
76
79
|
{
|
77
|
-
|
78
|
-
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
79
|
-
|
80
|
+
assert(cNokogiriSyntaxError);
|
80
81
|
/*
|
81
82
|
* The XML::SyntaxError is raised on parse errors
|
82
83
|
*/
|
83
|
-
|
84
|
-
VALUE klass = rb_define_class_under(xml, "SyntaxError", syntax_error_mommy);
|
85
|
-
cNokogiriXmlSyntaxError = klass;
|
86
|
-
|
84
|
+
cNokogiriXmlSyntaxError = rb_define_class_under(mNokogiriXml, "SyntaxError", cNokogiriSyntaxError);
|
87
85
|
}
|
data/ext/nokogiri/xml_text.c
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlText ;
|
2
4
|
|
3
5
|
/*
|
4
6
|
* call-seq:
|
@@ -6,7 +8,8 @@
|
|
6
8
|
*
|
7
9
|
* Create a new Text element on the +document+ with +content+
|
8
10
|
*/
|
9
|
-
static VALUE
|
11
|
+
static VALUE
|
12
|
+
new (int argc, VALUE *argv, VALUE klass)
|
10
13
|
{
|
11
14
|
xmlDocPtr doc;
|
12
15
|
xmlNodePtr node;
|
@@ -22,31 +25,24 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
|
|
22
25
|
node = xmlNewText((xmlChar *)StringValueCStr(string));
|
23
26
|
node->doc = doc->doc;
|
24
27
|
|
25
|
-
|
28
|
+
noko_xml_document_pin_node(node);
|
26
29
|
|
27
|
-
rb_node =
|
30
|
+
rb_node = noko_xml_node_wrap(klass, node) ;
|
28
31
|
rb_obj_call_init(rb_node, argc, argv);
|
29
32
|
|
30
|
-
if(rb_block_given_p()) rb_yield(rb_node);
|
33
|
+
if (rb_block_given_p()) { rb_yield(rb_node); }
|
31
34
|
|
32
35
|
return rb_node;
|
33
36
|
}
|
34
37
|
|
35
|
-
|
36
|
-
|
38
|
+
void
|
39
|
+
noko_init_xml_text()
|
37
40
|
{
|
38
|
-
|
39
|
-
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
40
|
-
/* */
|
41
|
-
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
42
|
-
VALUE char_data = rb_define_class_under(xml, "CharacterData", node);
|
43
|
-
|
41
|
+
assert(cNokogiriXmlCharacterData);
|
44
42
|
/*
|
45
43
|
* Wraps Text nodes.
|
46
44
|
*/
|
47
|
-
|
48
|
-
|
49
|
-
cNokogiriXmlText = klass;
|
45
|
+
cNokogiriXmlText = rb_define_class_under(mNokogiriXml, "Text", cNokogiriXmlCharacterData);
|
50
46
|
|
51
|
-
rb_define_singleton_method(
|
47
|
+
rb_define_singleton_method(cNokogiriXmlText, "new", new, -1);
|
52
48
|
}
|
@@ -1,4 +1,6 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlXpathContext;
|
2
4
|
|
3
5
|
/*
|
4
6
|
* these constants have matching declarations in
|
@@ -7,7 +9,8 @@
|
|
7
9
|
static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-builtin";
|
8
10
|
static const xmlChar *NOKOGIRI_BUILTIN_URI = (const xmlChar *)"https://www.nokogiri.org/default_ns/ruby/builtins";
|
9
11
|
|
10
|
-
static void
|
12
|
+
static void
|
13
|
+
deallocate(xmlXPathContextPtr ctx)
|
11
14
|
{
|
12
15
|
NOKOGIRI_DEBUG_START(ctx);
|
13
16
|
xmlXPathFreeContext(ctx);
|
@@ -15,23 +18,24 @@ static void deallocate(xmlXPathContextPtr ctx)
|
|
15
18
|
}
|
16
19
|
|
17
20
|
/* find a CSS class in an HTML element's `class` attribute */
|
18
|
-
|
21
|
+
static const xmlChar *
|
22
|
+
builtin_css_class(const xmlChar *str, const xmlChar *val)
|
19
23
|
{
|
20
24
|
int val_len;
|
21
25
|
|
22
|
-
if (str == NULL) { return(NULL); }
|
23
|
-
if (val == NULL) { return(NULL); }
|
26
|
+
if (str == NULL) { return (NULL); }
|
27
|
+
if (val == NULL) { return (NULL); }
|
24
28
|
|
25
29
|
val_len = xmlStrlen(val);
|
26
|
-
if (val_len == 0) { return(str); }
|
30
|
+
if (val_len == 0) { return (str); }
|
27
31
|
|
28
32
|
while (*str != 0) {
|
29
33
|
if ((*str == *val) && !xmlStrncmp(str, val, val_len)) {
|
30
|
-
const xmlChar*
|
34
|
+
const xmlChar *next_byte = str + val_len;
|
31
35
|
|
32
36
|
/* only match if the next byte is whitespace or end of string */
|
33
37
|
if ((*next_byte == 0) || (IS_BLANK_CH(*next_byte))) {
|
34
|
-
return((const xmlChar*)str);
|
38
|
+
return ((const xmlChar *)str);
|
35
39
|
}
|
36
40
|
}
|
37
41
|
|
@@ -46,11 +50,12 @@ const xmlChar* builtin_css_class(const xmlChar* str, const xmlChar *val)
|
|
46
50
|
}
|
47
51
|
}
|
48
52
|
|
49
|
-
return(NULL);
|
53
|
+
return (NULL);
|
50
54
|
}
|
51
55
|
|
52
56
|
/* xmlXPathFunction to wrap builtin_css_class() */
|
53
|
-
static void
|
57
|
+
static void
|
58
|
+
xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
|
54
59
|
{
|
55
60
|
xmlXPathObjectPtr hay, needle;
|
56
61
|
|
@@ -87,15 +92,16 @@ static void xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
|
|
87
92
|
*
|
88
93
|
* Register the namespace with +prefix+ and +uri+.
|
89
94
|
*/
|
90
|
-
static VALUE
|
95
|
+
static VALUE
|
96
|
+
register_ns(VALUE self, VALUE prefix, VALUE uri)
|
91
97
|
{
|
92
98
|
xmlXPathContextPtr ctx;
|
93
99
|
Data_Get_Struct(self, xmlXPathContext, ctx);
|
94
100
|
|
95
|
-
xmlXPathRegisterNs(
|
96
|
-
|
97
|
-
|
98
|
-
|
101
|
+
xmlXPathRegisterNs(ctx,
|
102
|
+
(const xmlChar *)StringValueCStr(prefix),
|
103
|
+
(const xmlChar *)StringValueCStr(uri)
|
104
|
+
);
|
99
105
|
return self;
|
100
106
|
}
|
101
107
|
|
@@ -105,23 +111,26 @@ static VALUE register_ns(VALUE self, VALUE prefix, VALUE uri)
|
|
105
111
|
*
|
106
112
|
* Register the variable +name+ with +value+.
|
107
113
|
*/
|
108
|
-
static VALUE
|
114
|
+
static VALUE
|
115
|
+
register_variable(VALUE self, VALUE name, VALUE value)
|
109
116
|
{
|
110
|
-
|
111
|
-
|
112
|
-
|
117
|
+
xmlXPathContextPtr ctx;
|
118
|
+
xmlXPathObjectPtr xmlValue;
|
119
|
+
Data_Get_Struct(self, xmlXPathContext, ctx);
|
113
120
|
|
114
|
-
|
121
|
+
xmlValue = xmlXPathNewCString(StringValueCStr(value));
|
115
122
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
123
|
+
xmlXPathRegisterVariable(ctx,
|
124
|
+
(const xmlChar *)StringValueCStr(name),
|
125
|
+
xmlValue
|
126
|
+
);
|
120
127
|
|
121
|
-
|
128
|
+
return self;
|
122
129
|
}
|
123
130
|
|
124
|
-
void
|
131
|
+
void
|
132
|
+
Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler,
|
133
|
+
const char *function_name)
|
125
134
|
{
|
126
135
|
int i;
|
127
136
|
VALUE result, doc;
|
@@ -144,7 +153,7 @@ void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr c
|
|
144
153
|
i = nargs - 1;
|
145
154
|
do {
|
146
155
|
obj = valuePop(ctx);
|
147
|
-
switch(obj->type) {
|
156
|
+
switch (obj->type) {
|
148
157
|
case XPATH_STRING:
|
149
158
|
argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
|
150
159
|
break;
|
@@ -155,23 +164,23 @@ void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr c
|
|
155
164
|
argv[i] = rb_float_new(obj->floatval);
|
156
165
|
break;
|
157
166
|
case XPATH_NODESET:
|
158
|
-
argv[i] =
|
167
|
+
argv[i] = noko_xml_node_set_wrap(obj->nodesetval, doc);
|
159
168
|
break;
|
160
169
|
default:
|
161
170
|
argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
|
162
171
|
}
|
163
172
|
xmlXPathFreeNodeSetList(obj);
|
164
|
-
} while(i-- > 0);
|
173
|
+
} while (i-- > 0);
|
165
174
|
}
|
166
175
|
|
167
|
-
result = rb_funcall2(handler, rb_intern((const char*)function_name), nargs, argv);
|
176
|
+
result = rb_funcall2(handler, rb_intern((const char *)function_name), nargs, argv);
|
168
177
|
|
169
178
|
for (i = 0 ; i < nargs ; ++i) {
|
170
179
|
rb_gc_unregister_address(&argv[i]);
|
171
180
|
}
|
172
181
|
free(argv);
|
173
182
|
|
174
|
-
switch(TYPE(result)) {
|
183
|
+
switch (TYPE(result)) {
|
175
184
|
case T_FLOAT:
|
176
185
|
case T_BIGNUM:
|
177
186
|
case T_FIXNUM:
|
@@ -179,8 +188,8 @@ void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr c
|
|
179
188
|
break;
|
180
189
|
case T_STRING:
|
181
190
|
xmlXPathReturnString(
|
182
|
-
|
183
|
-
|
191
|
+
ctx,
|
192
|
+
xmlCharStrdup(StringValueCStr(result))
|
184
193
|
);
|
185
194
|
break;
|
186
195
|
case T_TRUE:
|
@@ -191,18 +200,17 @@ void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr c
|
|
191
200
|
break;
|
192
201
|
case T_NIL:
|
193
202
|
break;
|
194
|
-
case T_ARRAY:
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
}
|
203
|
+
case T_ARRAY: {
|
204
|
+
VALUE args[2];
|
205
|
+
args[0] = doc;
|
206
|
+
args[1] = result;
|
207
|
+
node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
|
208
|
+
Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
|
209
|
+
xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
|
210
|
+
}
|
203
211
|
break;
|
204
212
|
case T_DATA:
|
205
|
-
if(rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
|
213
|
+
if (rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
|
206
214
|
Data_Get_Struct(result, xmlNodeSet, xml_node_set);
|
207
215
|
/* Copy the node set, otherwise it will get GC'd. */
|
208
216
|
xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
|
@@ -210,10 +218,11 @@ void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr c
|
|
210
218
|
}
|
211
219
|
default:
|
212
220
|
rb_raise(rb_eRuntimeError, "Invalid return type");
|
213
|
-
|
221
|
+
}
|
214
222
|
}
|
215
223
|
|
216
|
-
static void
|
224
|
+
static void
|
225
|
+
ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
|
217
226
|
{
|
218
227
|
VALUE handler = Qnil;
|
219
228
|
const char *function = NULL ;
|
@@ -224,26 +233,29 @@ static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
|
|
224
233
|
assert(ctx->context->function);
|
225
234
|
|
226
235
|
handler = (VALUE)(ctx->context->userData);
|
227
|
-
function = (const char*)(ctx->context->function);
|
236
|
+
function = (const char *)(ctx->context->function);
|
228
237
|
|
229
238
|
Nokogiri_marshal_xpath_funcall_and_return_values(ctx, nargs, handler, function);
|
230
239
|
}
|
231
240
|
|
232
|
-
static xmlXPathFunction
|
233
|
-
|
234
|
-
|
241
|
+
static xmlXPathFunction
|
242
|
+
lookup(void *ctx,
|
243
|
+
const xmlChar *name,
|
244
|
+
const xmlChar *ns_uri)
|
235
245
|
{
|
236
246
|
VALUE xpath_handler = (VALUE)ctx;
|
237
|
-
if(rb_respond_to(xpath_handler, rb_intern((const char *)name)))
|
247
|
+
if (rb_respond_to(xpath_handler, rb_intern((const char *)name))) {
|
238
248
|
return ruby_funcall;
|
249
|
+
}
|
239
250
|
|
240
251
|
return NULL;
|
241
252
|
}
|
242
253
|
|
243
|
-
NORETURN(static void xpath_generic_exception_handler(void *
|
244
|
-
static void
|
254
|
+
NORETURN(static void xpath_generic_exception_handler(void *ctx, const char *msg, ...));
|
255
|
+
static void
|
256
|
+
xpath_generic_exception_handler(void *ctx, const char *msg, ...)
|
245
257
|
{
|
246
|
-
char *
|
258
|
+
char *message;
|
247
259
|
|
248
260
|
va_list args;
|
249
261
|
va_start(args, msg);
|
@@ -259,7 +271,8 @@ static void xpath_generic_exception_handler(void * ctx, const char *msg, ...)
|
|
259
271
|
*
|
260
272
|
* Evaluate the +search_path+ returning an XML::XPath object.
|
261
273
|
*/
|
262
|
-
static VALUE
|
274
|
+
static VALUE
|
275
|
+
evaluate(int argc, VALUE *argv, VALUE self)
|
263
276
|
{
|
264
277
|
VALUE search_path, xpath_handler;
|
265
278
|
VALUE thing = Qnil;
|
@@ -269,12 +282,13 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
269
282
|
|
270
283
|
Data_Get_Struct(self, xmlXPathContext, ctx);
|
271
284
|
|
272
|
-
if(rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1)
|
285
|
+
if (rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1) {
|
273
286
|
xpath_handler = Qnil;
|
287
|
+
}
|
274
288
|
|
275
289
|
query = (xmlChar *)StringValueCStr(search_path);
|
276
290
|
|
277
|
-
if(Qnil != xpath_handler) {
|
291
|
+
if (Qnil != xpath_handler) {
|
278
292
|
/* FIXME: not sure if this is the correct place to shove private data. */
|
279
293
|
ctx->userData = (void *)xpath_handler;
|
280
294
|
xmlXPathRegisterFuncLookup(ctx, lookup, (void *)xpath_handler);
|
@@ -291,7 +305,7 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
291
305
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
292
306
|
xmlSetGenericErrorFunc(NULL, NULL);
|
293
307
|
|
294
|
-
if(xpath == NULL) {
|
308
|
+
if (xpath == NULL) {
|
295
309
|
xmlErrorPtr error = xmlGetLastError();
|
296
310
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
297
311
|
}
|
@@ -299,14 +313,14 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
299
313
|
assert(ctx->doc);
|
300
314
|
assert(DOC_RUBY_OBJECT_TEST(ctx->doc));
|
301
315
|
|
302
|
-
switch(xpath->type) {
|
316
|
+
switch (xpath->type) {
|
303
317
|
case XPATH_STRING:
|
304
318
|
thing = NOKOGIRI_STR_NEW2(xpath->stringval);
|
305
319
|
xmlFree(xpath->stringval);
|
306
320
|
break;
|
307
321
|
case XPATH_NODESET:
|
308
|
-
thing =
|
309
|
-
|
322
|
+
thing = noko_xml_node_set_wrap(xpath->nodesetval,
|
323
|
+
DOC_RUBY_OBJECT(ctx->doc));
|
310
324
|
break;
|
311
325
|
case XPATH_NUMBER:
|
312
326
|
thing = rb_float_new(xpath->floatval);
|
@@ -315,7 +329,7 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
315
329
|
thing = xpath->boolval == 1 ? Qtrue : Qfalse;
|
316
330
|
break;
|
317
331
|
default:
|
318
|
-
thing =
|
332
|
+
thing = noko_xml_node_set_wrap(NULL, DOC_RUBY_OBJECT(ctx->doc));
|
319
333
|
}
|
320
334
|
|
321
335
|
xmlXPathFreeNodeSetList(xpath);
|
@@ -329,7 +343,8 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
329
343
|
*
|
330
344
|
* Create a new XPathContext with +node+ as the reference point.
|
331
345
|
*/
|
332
|
-
static VALUE
|
346
|
+
static VALUE
|
347
|
+
new (VALUE klass, VALUE nodeobj)
|
333
348
|
{
|
334
349
|
xmlNodePtr node;
|
335
350
|
xmlXPathContextPtr ctx;
|
@@ -350,25 +365,19 @@ static VALUE new(VALUE klass, VALUE nodeobj)
|
|
350
365
|
return self;
|
351
366
|
}
|
352
367
|
|
353
|
-
|
354
|
-
|
368
|
+
void
|
369
|
+
noko_init_xml_xpath_context(void)
|
355
370
|
{
|
356
|
-
VALUE module = rb_define_module("Nokogiri");
|
357
|
-
|
358
|
-
/*
|
359
|
-
* Nokogiri::XML
|
360
|
-
*/
|
361
|
-
VALUE xml = rb_define_module_under(module, "XML");
|
362
|
-
|
363
371
|
/*
|
364
372
|
* XPathContext is the entry point for searching a Document by using XPath.
|
365
373
|
*/
|
366
|
-
|
374
|
+
cNokogiriXmlXpathContext = rb_define_class_under(mNokogiriXml, "XPathContext", rb_cObject);
|
375
|
+
|
376
|
+
rb_undef_alloc_func(cNokogiriXmlXpathContext);
|
367
377
|
|
368
|
-
cNokogiriXmlXpathContext
|
378
|
+
rb_define_singleton_method(cNokogiriXmlXpathContext, "new", new, 1);
|
369
379
|
|
370
|
-
|
371
|
-
rb_define_method(
|
372
|
-
rb_define_method(
|
373
|
-
rb_define_method(klass, "register_ns", register_ns, 2);
|
380
|
+
rb_define_method(cNokogiriXmlXpathContext, "evaluate", evaluate, -1);
|
381
|
+
rb_define_method(cNokogiriXmlXpathContext, "register_variable", register_variable, 2);
|
382
|
+
rb_define_method(cNokogiriXmlXpathContext, "register_ns", register_ns, 2);
|
374
383
|
}
|