nokogiri 1.10.10 → 1.14.3-aarch64-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 +44 -0
- data/LICENSE-DEPENDENCIES.md +1632 -1022
- data/LICENSE.md +1 -1
- data/README.md +185 -96
- data/bin/nokogiri +63 -50
- data/dependencies.yml +33 -66
- data/ext/nokogiri/depend +38 -358
- data/ext/nokogiri/extconf.rb +819 -421
- data/ext/nokogiri/gumbo.c +594 -0
- data/ext/nokogiri/html4_document.c +166 -0
- 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 +114 -0
- data/ext/nokogiri/html4_sax_push_parser.c +95 -0
- data/ext/nokogiri/include/libexslt/exslt.h +108 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +63 -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 +204 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +172 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +128 -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 +81 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +232 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +153 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +499 -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 +186 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1244 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +656 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +218 -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 +91 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1312 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +463 -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 +368 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +947 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +77 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +226 -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 +152 -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 +503 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +575 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +137 -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 +1982 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +179 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +64 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +310 -0
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +228 -104
- data/ext/nokogiri/nokogiri.h +204 -90
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +17 -17
- data/ext/nokogiri/xml_attribute_decl.c +22 -22
- data/ext/nokogiri/xml_cdata.c +15 -20
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +306 -225
- data/ext/nokogiri/xml_document_fragment.c +12 -16
- data/ext/nokogiri/xml_dtd.c +64 -58
- data/ext/nokogiri/xml_element_content.c +33 -28
- data/ext/nokogiri/xml_element_decl.c +26 -26
- data/ext/nokogiri/xml_encoding_handler.c +45 -20
- data/ext/nokogiri/xml_entity_decl.c +37 -35
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +136 -61
- data/ext/nokogiri/xml_node.c +1344 -672
- data/ext/nokogiri/xml_node_set.c +178 -168
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +316 -190
- data/ext/nokogiri/xml_relax_ng.c +52 -30
- data/ext/nokogiri/xml_sax_parser.c +130 -124
- data/ext/nokogiri/xml_sax_parser_context.c +110 -89
- data/ext/nokogiri/xml_sax_push_parser.c +36 -29
- data/ext/nokogiri/xml_schema.c +98 -50
- data/ext/nokogiri/xml_syntax_error.c +42 -21
- data/ext/nokogiri/xml_text.c +14 -18
- data/ext/nokogiri/xml_xpath_context.c +263 -148
- data/ext/nokogiri/xslt_stylesheet.c +271 -178
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +111 -0
- data/gumbo-parser/THANKS +27 -0
- 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/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +10 -8
- data/lib/nokogiri/css/parser.rb +397 -377
- data/lib/nokogiri/css/parser.y +250 -245
- data/lib/nokogiri/css/parser_extras.rb +54 -49
- data/lib/nokogiri/css/syntax_error.rb +3 -1
- data/lib/nokogiri/css/tokenizer.rb +5 -3
- data/lib/nokogiri/css/tokenizer.rex +3 -2
- data/lib/nokogiri/css/xpath_visitor.rb +223 -94
- data/lib/nokogiri/css.rb +56 -17
- data/lib/nokogiri/decorators/slop.rb +9 -7
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +32 -0
- data/lib/nokogiri/gumbo.rb +15 -0
- data/lib/nokogiri/html.rb +38 -27
- data/lib/nokogiri/{html → html4}/builder.rb +4 -2
- data/lib/nokogiri/html4/document.rb +214 -0
- data/lib/nokogiri/html4/document_fragment.rb +54 -0
- data/lib/nokogiri/{html → html4}/element_description.rb +3 -1
- data/lib/nokogiri/html4/element_description_defaults.rb +572 -0
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/{html → html4}/entity_lookup.rb +4 -2
- data/lib/nokogiri/{html → html4}/sax/parser.rb +17 -16
- data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
- data/lib/nokogiri/{html → html4}/sax/push_parser.rb +12 -11
- data/lib/nokogiri/html4.rb +47 -0
- data/lib/nokogiri/html5/document.rb +168 -0
- data/lib/nokogiri/html5/document_fragment.rb +90 -0
- data/lib/nokogiri/html5/node.rb +98 -0
- data/lib/nokogiri/html5.rb +389 -0
- data/lib/nokogiri/jruby/dependencies.rb +3 -0
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/syntax_error.rb +2 -0
- data/lib/nokogiri/version/constant.rb +6 -0
- data/lib/nokogiri/version/info.rb +223 -0
- data/lib/nokogiri/version.rb +3 -108
- data/lib/nokogiri/xml/attr.rb +55 -3
- data/lib/nokogiri/xml/attribute_decl.rb +3 -1
- data/lib/nokogiri/xml/builder.rb +75 -34
- data/lib/nokogiri/xml/cdata.rb +3 -1
- data/lib/nokogiri/xml/character_data.rb +2 -0
- data/lib/nokogiri/xml/document.rb +312 -126
- data/lib/nokogiri/xml/document_fragment.rb +93 -48
- data/lib/nokogiri/xml/dtd.rb +4 -2
- data/lib/nokogiri/xml/element_content.rb +2 -0
- data/lib/nokogiri/xml/element_decl.rb +3 -1
- data/lib/nokogiri/xml/entity_decl.rb +4 -2
- data/lib/nokogiri/xml/entity_reference.rb +2 -0
- data/lib/nokogiri/xml/namespace.rb +45 -0
- data/lib/nokogiri/xml/node/save_options.rb +15 -8
- data/lib/nokogiri/xml/node.rb +1067 -406
- data/lib/nokogiri/xml/node_set.rb +135 -59
- data/lib/nokogiri/xml/notation.rb +13 -0
- data/lib/nokogiri/xml/parse_options.rb +145 -52
- data/lib/nokogiri/xml/pp/character_data.rb +9 -6
- data/lib/nokogiri/xml/pp/node.rb +27 -26
- data/lib/nokogiri/xml/pp.rb +4 -2
- data/lib/nokogiri/xml/processing_instruction.rb +4 -1
- data/lib/nokogiri/xml/reader.rb +21 -28
- data/lib/nokogiri/xml/relax_ng.rb +8 -2
- data/lib/nokogiri/xml/sax/document.rb +45 -49
- data/lib/nokogiri/xml/sax/parser.rb +39 -36
- data/lib/nokogiri/xml/sax/parser_context.rb +8 -3
- data/lib/nokogiri/xml/sax/push_parser.rb +6 -5
- data/lib/nokogiri/xml/sax.rb +6 -4
- data/lib/nokogiri/xml/schema.rb +19 -9
- data/lib/nokogiri/xml/searchable.rb +112 -72
- data/lib/nokogiri/xml/syntax_error.rb +6 -4
- data/lib/nokogiri/xml/text.rb +2 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +4 -2
- data/lib/nokogiri/xml/xpath.rb +15 -4
- data/lib/nokogiri/xml/xpath_context.rb +3 -3
- data/lib/nokogiri/xml.rb +38 -37
- data/lib/nokogiri/xslt/stylesheet.rb +3 -1
- data/lib/nokogiri/xslt.rb +29 -20
- data/lib/nokogiri.rb +48 -72
- data/lib/xsd/xmlparser/nokogiri.rb +29 -25
- metadata +146 -307
- data/ext/nokogiri/html_document.c +0 -170
- 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 -116
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.c +0 -87
- 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 -61
- 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 -13
- 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/document.rb +0 -335
- data/lib/nokogiri/html/document_fragment.rb +0 -49
- data/lib/nokogiri/html/element_description_defaults.rb +0 -671
- data/lib/nokogiri/html/sax/parser_context.rb +0 -16
- data/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch +0 -78
- data/patches/libxml2/0002-Remove-script-macro-support.patch +0 -40
- data/patches/libxml2/0003-Update-entities-to-remove-handling-of-ssi.patch +0 -44
- data/patches/libxml2/0004-libxml2.la-is-in-top_builddir.patch +0 -25
- data/patches/libxml2/0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch +0 -32
- data/ports/archives/libxml2-2.9.10.tar.gz +0 -0
- data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
@@ -1,29 +1,127 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
2
|
|
3
|
-
|
3
|
+
VALUE cNokogiriXmlXpathContext;
|
4
|
+
|
5
|
+
/*
|
6
|
+
* these constants have matching declarations in
|
7
|
+
* ext/java/nokogiri/internals/NokogiriNamespaceContext.java
|
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";
|
11
|
+
static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-builtin";
|
12
|
+
static const xmlChar *NOKOGIRI_BUILTIN_URI = (const xmlChar *)"https://www.nokogiri.org/default_ns/ruby/builtins";
|
4
13
|
|
5
|
-
static void
|
14
|
+
static void
|
15
|
+
xml_xpath_context_deallocate(xmlXPathContextPtr ctx)
|
6
16
|
{
|
7
|
-
NOKOGIRI_DEBUG_START(ctx);
|
8
17
|
xmlXPathFreeContext(ctx);
|
9
|
-
NOKOGIRI_DEBUG_END(ctx);
|
10
18
|
}
|
11
19
|
|
20
|
+
/* find a CSS class in an HTML element's `class` attribute */
|
21
|
+
static const xmlChar *
|
22
|
+
builtin_css_class(const xmlChar *str, const xmlChar *val)
|
23
|
+
{
|
24
|
+
int val_len;
|
25
|
+
|
26
|
+
if (str == NULL) { return (NULL); }
|
27
|
+
if (val == NULL) { return (NULL); }
|
28
|
+
|
29
|
+
val_len = xmlStrlen(val);
|
30
|
+
if (val_len == 0) { return (str); }
|
31
|
+
|
32
|
+
while (*str != 0) {
|
33
|
+
if ((*str == *val) && !xmlStrncmp(str, val, val_len)) {
|
34
|
+
const xmlChar *next_byte = str + val_len;
|
35
|
+
|
36
|
+
/* only match if the next byte is whitespace or end of string */
|
37
|
+
if ((*next_byte == 0) || (IS_BLANK_CH(*next_byte))) {
|
38
|
+
return ((const xmlChar *)str);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
/* advance str to whitespace */
|
43
|
+
while ((*str != 0) && !IS_BLANK_CH(*str)) {
|
44
|
+
str++;
|
45
|
+
}
|
46
|
+
|
47
|
+
/* advance str to start of next word or end of string */
|
48
|
+
while ((*str != 0) && IS_BLANK_CH(*str)) {
|
49
|
+
str++;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
return (NULL);
|
54
|
+
}
|
55
|
+
|
56
|
+
/* xmlXPathFunction to wrap builtin_css_class() */
|
57
|
+
static void
|
58
|
+
xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
|
59
|
+
{
|
60
|
+
xmlXPathObjectPtr hay, needle;
|
61
|
+
|
62
|
+
CHECK_ARITY(2);
|
63
|
+
|
64
|
+
CAST_TO_STRING;
|
65
|
+
needle = valuePop(ctxt);
|
66
|
+
if ((needle == NULL) || (needle->type != XPATH_STRING)) {
|
67
|
+
xmlXPathFreeObject(needle);
|
68
|
+
XP_ERROR(XPATH_INVALID_TYPE);
|
69
|
+
}
|
70
|
+
|
71
|
+
CAST_TO_STRING;
|
72
|
+
hay = valuePop(ctxt);
|
73
|
+
if ((hay == NULL) || (hay->type != XPATH_STRING)) {
|
74
|
+
xmlXPathFreeObject(hay);
|
75
|
+
xmlXPathFreeObject(needle);
|
76
|
+
XP_ERROR(XPATH_INVALID_TYPE);
|
77
|
+
}
|
78
|
+
|
79
|
+
if (builtin_css_class(hay->stringval, needle->stringval)) {
|
80
|
+
valuePush(ctxt, xmlXPathNewBoolean(1));
|
81
|
+
} else {
|
82
|
+
valuePush(ctxt, xmlXPathNewBoolean(0));
|
83
|
+
}
|
84
|
+
|
85
|
+
xmlXPathFreeObject(hay);
|
86
|
+
xmlXPathFreeObject(needle);
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
/* xmlXPathFunction to select nodes whose local name matches, for HTML5 CSS queries that should ignore namespaces */
|
91
|
+
static void
|
92
|
+
xpath_builtin_local_name_is(xmlXPathParserContextPtr ctxt, int nargs)
|
93
|
+
{
|
94
|
+
xmlXPathObjectPtr element_name;
|
95
|
+
|
96
|
+
assert(ctxt->context->node);
|
97
|
+
|
98
|
+
CHECK_ARITY(1);
|
99
|
+
CAST_TO_STRING;
|
100
|
+
CHECK_TYPE(XPATH_STRING);
|
101
|
+
element_name = valuePop(ctxt);
|
102
|
+
|
103
|
+
valuePush(ctxt, xmlXPathNewBoolean(xmlStrEqual(ctxt->context->node->name, element_name->stringval)));
|
104
|
+
|
105
|
+
xmlXPathFreeObject(element_name);
|
106
|
+
}
|
107
|
+
|
108
|
+
|
12
109
|
/*
|
13
110
|
* call-seq:
|
14
111
|
* register_ns(prefix, uri)
|
15
112
|
*
|
16
113
|
* Register the namespace with +prefix+ and +uri+.
|
17
114
|
*/
|
18
|
-
static VALUE
|
115
|
+
static VALUE
|
116
|
+
rb_xml_xpath_context_register_ns(VALUE self, VALUE prefix, VALUE uri)
|
19
117
|
{
|
20
118
|
xmlXPathContextPtr ctx;
|
21
119
|
Data_Get_Struct(self, xmlXPathContext, ctx);
|
22
120
|
|
23
|
-
xmlXPathRegisterNs(
|
24
|
-
|
25
|
-
|
26
|
-
|
121
|
+
xmlXPathRegisterNs(ctx,
|
122
|
+
(const xmlChar *)StringValueCStr(prefix),
|
123
|
+
(const xmlChar *)StringValueCStr(uri)
|
124
|
+
);
|
27
125
|
return self;
|
28
126
|
}
|
29
127
|
|
@@ -33,83 +131,103 @@ static VALUE register_ns(VALUE self, VALUE prefix, VALUE uri)
|
|
33
131
|
*
|
34
132
|
* Register the variable +name+ with +value+.
|
35
133
|
*/
|
36
|
-
static VALUE
|
134
|
+
static VALUE
|
135
|
+
rb_xml_xpath_context_register_variable(VALUE self, VALUE name, VALUE value)
|
37
136
|
{
|
38
|
-
|
39
|
-
|
40
|
-
|
137
|
+
xmlXPathContextPtr ctx;
|
138
|
+
xmlXPathObjectPtr xmlValue;
|
139
|
+
Data_Get_Struct(self, xmlXPathContext, ctx);
|
41
140
|
|
42
|
-
|
141
|
+
xmlValue = xmlXPathNewCString(StringValueCStr(value));
|
43
142
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
143
|
+
xmlXPathRegisterVariable(ctx,
|
144
|
+
(const xmlChar *)StringValueCStr(name),
|
145
|
+
xmlValue
|
146
|
+
);
|
48
147
|
|
49
|
-
|
148
|
+
return self;
|
50
149
|
}
|
51
150
|
|
52
|
-
|
151
|
+
|
152
|
+
/*
|
153
|
+
* convert an XPath object into a Ruby object of the appropriate type.
|
154
|
+
* returns Qundef if no conversion was possible.
|
155
|
+
*/
|
156
|
+
static VALUE
|
157
|
+
xpath2ruby(xmlXPathObjectPtr c_xpath_object, xmlXPathContextPtr ctx)
|
53
158
|
{
|
54
|
-
|
55
|
-
|
159
|
+
VALUE rb_retval;
|
160
|
+
|
161
|
+
assert(ctx->doc);
|
162
|
+
assert(DOC_RUBY_OBJECT_TEST(ctx->doc));
|
163
|
+
|
164
|
+
switch (c_xpath_object->type) {
|
165
|
+
case XPATH_STRING:
|
166
|
+
rb_retval = NOKOGIRI_STR_NEW2(c_xpath_object->stringval);
|
167
|
+
xmlFree(c_xpath_object->stringval);
|
168
|
+
return rb_retval;
|
169
|
+
|
170
|
+
case XPATH_NODESET:
|
171
|
+
return noko_xml_node_set_wrap(c_xpath_object->nodesetval,
|
172
|
+
DOC_RUBY_OBJECT(ctx->doc));
|
173
|
+
|
174
|
+
case XPATH_NUMBER:
|
175
|
+
return rb_float_new(c_xpath_object->floatval);
|
176
|
+
|
177
|
+
case XPATH_BOOLEAN:
|
178
|
+
return (c_xpath_object->boolval == 1) ? Qtrue : Qfalse;
|
179
|
+
|
180
|
+
default:
|
181
|
+
return Qundef;
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
void
|
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
|
+
)
|
192
|
+
{
|
193
|
+
VALUE rb_retval;
|
56
194
|
VALUE *argv;
|
57
|
-
VALUE
|
58
|
-
xmlNodeSetPtr
|
59
|
-
xmlXPathObjectPtr
|
195
|
+
VALUE rb_node_set = Qnil;
|
196
|
+
xmlNodeSetPtr c_node_set = NULL;
|
197
|
+
xmlXPathObjectPtr c_xpath_object;
|
60
198
|
|
61
199
|
assert(ctx->context->doc);
|
62
200
|
assert(DOC_RUBY_OBJECT_TEST(ctx->context->doc));
|
63
201
|
|
64
|
-
argv = (VALUE *)
|
65
|
-
for (
|
66
|
-
rb_gc_register_address(&argv[
|
202
|
+
argv = (VALUE *)ruby_xcalloc((size_t)argc, sizeof(VALUE));
|
203
|
+
for (int j = 0 ; j < argc ; ++j) {
|
204
|
+
rb_gc_register_address(&argv[j]);
|
67
205
|
}
|
68
206
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
case XPATH_STRING:
|
77
|
-
argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
|
78
|
-
break;
|
79
|
-
case XPATH_BOOLEAN:
|
80
|
-
argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
|
81
|
-
break;
|
82
|
-
case XPATH_NUMBER:
|
83
|
-
argv[i] = rb_float_new(obj->floatval);
|
84
|
-
break;
|
85
|
-
case XPATH_NODESET:
|
86
|
-
argv[i] = Nokogiri_wrap_xml_node_set(obj->nodesetval, doc);
|
87
|
-
break;
|
88
|
-
default:
|
89
|
-
argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
|
90
|
-
}
|
91
|
-
xmlXPathFreeNodeSetList(obj);
|
92
|
-
} while(i-- > 0);
|
207
|
+
for (int j = argc - 1 ; j >= 0 ; --j) {
|
208
|
+
c_xpath_object = valuePop(ctx);
|
209
|
+
argv[j] = xpath2ruby(c_xpath_object, ctx->context);
|
210
|
+
if (argv[j] == Qundef) {
|
211
|
+
argv[j] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(c_xpath_object));
|
212
|
+
}
|
213
|
+
xmlXPathFreeNodeSetList(c_xpath_object);
|
93
214
|
}
|
94
215
|
|
95
|
-
|
216
|
+
rb_retval = rb_funcall2(rb_xpath_handler, rb_intern((const char *)method_name), argc, argv);
|
96
217
|
|
97
|
-
for (
|
98
|
-
rb_gc_unregister_address(&argv[
|
218
|
+
for (int j = 0 ; j < argc ; ++j) {
|
219
|
+
rb_gc_unregister_address(&argv[j]);
|
99
220
|
}
|
100
|
-
|
221
|
+
ruby_xfree(argv);
|
101
222
|
|
102
|
-
switch(TYPE(
|
223
|
+
switch (TYPE(rb_retval)) {
|
103
224
|
case T_FLOAT:
|
104
225
|
case T_BIGNUM:
|
105
226
|
case T_FIXNUM:
|
106
|
-
xmlXPathReturnNumber(ctx, NUM2DBL(
|
227
|
+
xmlXPathReturnNumber(ctx, NUM2DBL(rb_retval));
|
107
228
|
break;
|
108
229
|
case T_STRING:
|
109
|
-
xmlXPathReturnString(
|
110
|
-
ctx,
|
111
|
-
xmlCharStrdup(StringValueCStr(result))
|
112
|
-
);
|
230
|
+
xmlXPathReturnString(ctx, xmlCharStrdup(StringValueCStr(rb_retval)));
|
113
231
|
break;
|
114
232
|
case T_TRUE:
|
115
233
|
xmlXPathReturnTrue(ctx);
|
@@ -119,66 +237,76 @@ void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr c
|
|
119
237
|
break;
|
120
238
|
case T_NIL:
|
121
239
|
break;
|
122
|
-
case T_ARRAY:
|
123
|
-
{
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
|
129
|
-
xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
|
130
|
-
}
|
240
|
+
case T_ARRAY: {
|
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));
|
245
|
+
}
|
131
246
|
break;
|
132
247
|
case T_DATA:
|
133
|
-
if(rb_obj_is_kind_of(
|
134
|
-
Data_Get_Struct(
|
248
|
+
if (rb_obj_is_kind_of(rb_retval, cNokogiriXmlNodeSet)) {
|
249
|
+
Data_Get_Struct(rb_retval, xmlNodeSet, c_node_set);
|
135
250
|
/* Copy the node set, otherwise it will get GC'd. */
|
136
|
-
xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL,
|
251
|
+
xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, c_node_set));
|
137
252
|
break;
|
138
253
|
}
|
139
254
|
default:
|
140
255
|
rb_raise(rb_eRuntimeError, "Invalid return type");
|
141
|
-
|
256
|
+
}
|
142
257
|
}
|
143
258
|
|
144
|
-
static void
|
259
|
+
static void
|
260
|
+
method_caller(xmlXPathParserContextPtr ctx, int argc)
|
145
261
|
{
|
146
|
-
VALUE
|
147
|
-
const char *
|
262
|
+
VALUE rb_xpath_handler = Qnil;
|
263
|
+
const char *method_name = NULL ;
|
148
264
|
|
149
265
|
assert(ctx);
|
150
266
|
assert(ctx->context);
|
151
267
|
assert(ctx->context->userData);
|
152
268
|
assert(ctx->context->function);
|
153
269
|
|
154
|
-
|
155
|
-
|
270
|
+
rb_xpath_handler = (VALUE)(ctx->context->userData);
|
271
|
+
method_name = (const char *)(ctx->context->function);
|
156
272
|
|
157
|
-
Nokogiri_marshal_xpath_funcall_and_return_values(ctx,
|
273
|
+
Nokogiri_marshal_xpath_funcall_and_return_values(ctx, argc, rb_xpath_handler, method_name);
|
158
274
|
}
|
159
275
|
|
160
|
-
static xmlXPathFunction
|
161
|
-
|
162
|
-
const xmlChar* ns_uri )
|
276
|
+
static xmlXPathFunction
|
277
|
+
handler_lookup(void *ctx, const xmlChar *c_name, const xmlChar *c_ns_uri)
|
163
278
|
{
|
164
|
-
VALUE
|
165
|
-
if(rb_respond_to(
|
166
|
-
return
|
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;
|
282
|
+
}
|
167
283
|
|
168
284
|
return NULL;
|
169
285
|
}
|
170
286
|
|
171
|
-
|
172
|
-
static void
|
287
|
+
PRINTFLIKE_DECL(2, 3)
|
288
|
+
static void
|
289
|
+
generic_exception_pusher(void *ctx, const char *msg, ...)
|
173
290
|
{
|
174
|
-
|
291
|
+
VALUE rb_errors = (VALUE)ctx;
|
292
|
+
VALUE rb_message;
|
293
|
+
VALUE rb_exception;
|
175
294
|
|
295
|
+
Check_Type(rb_errors, T_ARRAY);
|
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
|
176
302
|
va_list args;
|
177
303
|
va_start(args, msg);
|
178
|
-
|
304
|
+
rb_message = rb_vsprintf(msg, args);
|
179
305
|
va_end(args);
|
306
|
+
#endif
|
180
307
|
|
181
|
-
|
308
|
+
rb_exception = rb_exc_new_str(cNokogiriXmlXpathSyntaxError, rb_message);
|
309
|
+
rb_ary_push(rb_errors, rb_exception);
|
182
310
|
}
|
183
311
|
|
184
312
|
/*
|
@@ -187,68 +315,50 @@ static void xpath_generic_exception_handler(void * ctx, const char *msg, ...)
|
|
187
315
|
*
|
188
316
|
* Evaluate the +search_path+ returning an XML::XPath object.
|
189
317
|
*/
|
190
|
-
static VALUE
|
318
|
+
static VALUE
|
319
|
+
rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE self)
|
191
320
|
{
|
192
321
|
VALUE search_path, xpath_handler;
|
193
|
-
VALUE
|
322
|
+
VALUE retval = Qnil;
|
194
323
|
xmlXPathContextPtr ctx;
|
195
324
|
xmlXPathObjectPtr xpath;
|
196
325
|
xmlChar *query;
|
326
|
+
VALUE errors = rb_ary_new();
|
197
327
|
|
198
328
|
Data_Get_Struct(self, xmlXPathContext, ctx);
|
199
329
|
|
200
|
-
if(rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1)
|
330
|
+
if (rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1) {
|
201
331
|
xpath_handler = Qnil;
|
332
|
+
}
|
202
333
|
|
203
334
|
query = (xmlChar *)StringValueCStr(search_path);
|
204
335
|
|
205
|
-
if(Qnil != xpath_handler) {
|
336
|
+
if (Qnil != xpath_handler) {
|
206
337
|
/* FIXME: not sure if this is the correct place to shove private data. */
|
207
338
|
ctx->userData = (void *)xpath_handler;
|
208
|
-
xmlXPathRegisterFuncLookup(ctx,
|
339
|
+
xmlXPathRegisterFuncLookup(ctx, handler_lookup, (void *)xpath_handler);
|
209
340
|
}
|
210
341
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
/* For some reason, xmlXPathEvalExpression will blow up with a generic error */
|
215
|
-
/* when there is a non existent function. */
|
216
|
-
xmlSetGenericErrorFunc(NULL, xpath_generic_exception_handler);
|
342
|
+
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
343
|
+
xmlSetGenericErrorFunc((void *)errors, generic_exception_pusher);
|
217
344
|
|
218
345
|
xpath = xmlXPathEvalExpression(query, ctx);
|
346
|
+
|
219
347
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
220
348
|
xmlSetGenericErrorFunc(NULL, NULL);
|
221
349
|
|
222
|
-
if(xpath == NULL) {
|
223
|
-
|
224
|
-
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
350
|
+
if (xpath == NULL) {
|
351
|
+
rb_exc_raise(rb_ary_entry(errors, 0));
|
225
352
|
}
|
226
353
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
switch(xpath->type) {
|
231
|
-
case XPATH_STRING:
|
232
|
-
thing = NOKOGIRI_STR_NEW2(xpath->stringval);
|
233
|
-
xmlFree(xpath->stringval);
|
234
|
-
break;
|
235
|
-
case XPATH_NODESET:
|
236
|
-
thing = Nokogiri_wrap_xml_node_set(xpath->nodesetval,
|
237
|
-
DOC_RUBY_OBJECT(ctx->doc));
|
238
|
-
break;
|
239
|
-
case XPATH_NUMBER:
|
240
|
-
thing = rb_float_new(xpath->floatval);
|
241
|
-
break;
|
242
|
-
case XPATH_BOOLEAN:
|
243
|
-
thing = xpath->boolval == 1 ? Qtrue : Qfalse;
|
244
|
-
break;
|
245
|
-
default:
|
246
|
-
thing = Nokogiri_wrap_xml_node_set(NULL, DOC_RUBY_OBJECT(ctx->doc));
|
354
|
+
retval = xpath2ruby(xpath, ctx);
|
355
|
+
if (retval == Qundef) {
|
356
|
+
retval = noko_xml_node_set_wrap(NULL, DOC_RUBY_OBJECT(ctx->doc));
|
247
357
|
}
|
248
358
|
|
249
359
|
xmlXPathFreeNodeSetList(xpath);
|
250
360
|
|
251
|
-
return
|
361
|
+
return retval;
|
252
362
|
}
|
253
363
|
|
254
364
|
/*
|
@@ -257,42 +367,47 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
257
367
|
*
|
258
368
|
* Create a new XPathContext with +node+ as the reference point.
|
259
369
|
*/
|
260
|
-
static VALUE
|
370
|
+
static VALUE
|
371
|
+
rb_xml_xpath_context_new(VALUE klass, VALUE nodeobj)
|
261
372
|
{
|
262
373
|
xmlNodePtr node;
|
263
374
|
xmlXPathContextPtr ctx;
|
264
375
|
VALUE self;
|
265
376
|
|
266
|
-
|
377
|
+
Noko_Node_Get_Struct(nodeobj, xmlNode, node);
|
267
378
|
|
268
|
-
|
379
|
+
#if LIBXML_VERSION < 21000
|
380
|
+
/* deprecated in 40483d0 */
|
381
|
+
xmlXPathInit();
|
382
|
+
#endif
|
269
383
|
|
270
384
|
ctx = xmlXPathNewContext(node->doc);
|
271
385
|
ctx->node = node;
|
272
|
-
|
273
|
-
|
386
|
+
|
387
|
+
xmlXPathRegisterNs(ctx, NOKOGIRI_PREFIX, NOKOGIRI_URI);
|
388
|
+
xmlXPathRegisterNs(ctx, NOKOGIRI_BUILTIN_PREFIX, NOKOGIRI_BUILTIN_URI);
|
389
|
+
xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"css-class", NOKOGIRI_BUILTIN_URI,
|
390
|
+
xpath_builtin_css_class);
|
391
|
+
xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"local-name-is", NOKOGIRI_BUILTIN_URI,
|
392
|
+
xpath_builtin_local_name_is);
|
393
|
+
|
394
|
+
self = Data_Wrap_Struct(klass, 0, xml_xpath_context_deallocate, ctx);
|
274
395
|
return self;
|
275
396
|
}
|
276
397
|
|
277
|
-
|
278
|
-
|
398
|
+
void
|
399
|
+
noko_init_xml_xpath_context(void)
|
279
400
|
{
|
280
|
-
VALUE module = rb_define_module("Nokogiri");
|
281
|
-
|
282
|
-
/*
|
283
|
-
* Nokogiri::XML
|
284
|
-
*/
|
285
|
-
VALUE xml = rb_define_module_under(module, "XML");
|
286
|
-
|
287
401
|
/*
|
288
402
|
* XPathContext is the entry point for searching a Document by using XPath.
|
289
403
|
*/
|
290
|
-
|
404
|
+
cNokogiriXmlXpathContext = rb_define_class_under(mNokogiriXml, "XPathContext", rb_cObject);
|
405
|
+
|
406
|
+
rb_undef_alloc_func(cNokogiriXmlXpathContext);
|
291
407
|
|
292
|
-
cNokogiriXmlXpathContext
|
408
|
+
rb_define_singleton_method(cNokogiriXmlXpathContext, "new", rb_xml_xpath_context_new, 1);
|
293
409
|
|
294
|
-
|
295
|
-
rb_define_method(
|
296
|
-
rb_define_method(
|
297
|
-
rb_define_method(klass, "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);
|
298
413
|
}
|