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.

Files changed (251) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +44 -0
  3. data/LICENSE-DEPENDENCIES.md +1632 -1022
  4. data/LICENSE.md +1 -1
  5. data/README.md +185 -96
  6. data/bin/nokogiri +63 -50
  7. data/dependencies.yml +33 -66
  8. data/ext/nokogiri/depend +38 -358
  9. data/ext/nokogiri/extconf.rb +819 -421
  10. data/ext/nokogiri/gumbo.c +594 -0
  11. data/ext/nokogiri/html4_document.c +166 -0
  12. data/ext/nokogiri/html4_element_description.c +294 -0
  13. data/ext/nokogiri/html4_entity_lookup.c +37 -0
  14. data/ext/nokogiri/html4_sax_parser_context.c +114 -0
  15. data/ext/nokogiri/html4_sax_push_parser.c +95 -0
  16. data/ext/nokogiri/include/libexslt/exslt.h +108 -0
  17. data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
  18. data/ext/nokogiri/include/libexslt/exsltexports.h +63 -0
  19. data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
  20. data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
  21. data/ext/nokogiri/include/libxml2/libxml/SAX.h +204 -0
  22. data/ext/nokogiri/include/libxml2/libxml/SAX2.h +172 -0
  23. data/ext/nokogiri/include/libxml2/libxml/c14n.h +128 -0
  24. data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
  25. data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
  26. data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
  27. data/ext/nokogiri/include/libxml2/libxml/dict.h +81 -0
  28. data/ext/nokogiri/include/libxml2/libxml/encoding.h +232 -0
  29. data/ext/nokogiri/include/libxml2/libxml/entities.h +153 -0
  30. data/ext/nokogiri/include/libxml2/libxml/globals.h +499 -0
  31. data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
  32. data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
  33. data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +186 -0
  34. data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
  35. data/ext/nokogiri/include/libxml2/libxml/parser.h +1244 -0
  36. data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +656 -0
  37. data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
  38. data/ext/nokogiri/include/libxml2/libxml/relaxng.h +218 -0
  39. data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
  40. data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
  41. data/ext/nokogiri/include/libxml2/libxml/threads.h +91 -0
  42. data/ext/nokogiri/include/libxml2/libxml/tree.h +1312 -0
  43. data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
  44. data/ext/nokogiri/include/libxml2/libxml/valid.h +463 -0
  45. data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
  46. data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
  47. data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +368 -0
  48. data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
  49. data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +947 -0
  50. data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +77 -0
  51. data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +226 -0
  52. data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
  53. data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
  54. data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
  55. data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
  56. data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
  57. data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +152 -0
  58. data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
  59. data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
  60. data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +503 -0
  61. data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
  62. data/ext/nokogiri/include/libxml2/libxml/xpath.h +575 -0
  63. data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
  64. data/ext/nokogiri/include/libxml2/libxml/xpointer.h +137 -0
  65. data/ext/nokogiri/include/libxslt/attributes.h +38 -0
  66. data/ext/nokogiri/include/libxslt/documents.h +93 -0
  67. data/ext/nokogiri/include/libxslt/extensions.h +262 -0
  68. data/ext/nokogiri/include/libxslt/extra.h +72 -0
  69. data/ext/nokogiri/include/libxslt/functions.h +78 -0
  70. data/ext/nokogiri/include/libxslt/imports.h +75 -0
  71. data/ext/nokogiri/include/libxslt/keys.h +53 -0
  72. data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
  73. data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
  74. data/ext/nokogiri/include/libxslt/pattern.h +84 -0
  75. data/ext/nokogiri/include/libxslt/preproc.h +43 -0
  76. data/ext/nokogiri/include/libxslt/security.h +104 -0
  77. data/ext/nokogiri/include/libxslt/templates.h +77 -0
  78. data/ext/nokogiri/include/libxslt/transform.h +207 -0
  79. data/ext/nokogiri/include/libxslt/variables.h +118 -0
  80. data/ext/nokogiri/include/libxslt/xslt.h +110 -0
  81. data/ext/nokogiri/include/libxslt/xsltInternals.h +1982 -0
  82. data/ext/nokogiri/include/libxslt/xsltconfig.h +179 -0
  83. data/ext/nokogiri/include/libxslt/xsltexports.h +64 -0
  84. data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
  85. data/ext/nokogiri/include/libxslt/xsltutils.h +310 -0
  86. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  87. data/ext/nokogiri/nokogiri.c +228 -104
  88. data/ext/nokogiri/nokogiri.h +204 -90
  89. data/ext/nokogiri/test_global_handlers.c +40 -0
  90. data/ext/nokogiri/xml_attr.c +17 -17
  91. data/ext/nokogiri/xml_attribute_decl.c +22 -22
  92. data/ext/nokogiri/xml_cdata.c +15 -20
  93. data/ext/nokogiri/xml_comment.c +19 -26
  94. data/ext/nokogiri/xml_document.c +306 -225
  95. data/ext/nokogiri/xml_document_fragment.c +12 -16
  96. data/ext/nokogiri/xml_dtd.c +64 -58
  97. data/ext/nokogiri/xml_element_content.c +33 -28
  98. data/ext/nokogiri/xml_element_decl.c +26 -26
  99. data/ext/nokogiri/xml_encoding_handler.c +45 -20
  100. data/ext/nokogiri/xml_entity_decl.c +37 -35
  101. data/ext/nokogiri/xml_entity_reference.c +16 -18
  102. data/ext/nokogiri/xml_namespace.c +136 -61
  103. data/ext/nokogiri/xml_node.c +1344 -672
  104. data/ext/nokogiri/xml_node_set.c +178 -168
  105. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  106. data/ext/nokogiri/xml_reader.c +316 -190
  107. data/ext/nokogiri/xml_relax_ng.c +52 -30
  108. data/ext/nokogiri/xml_sax_parser.c +130 -124
  109. data/ext/nokogiri/xml_sax_parser_context.c +110 -89
  110. data/ext/nokogiri/xml_sax_push_parser.c +36 -29
  111. data/ext/nokogiri/xml_schema.c +98 -50
  112. data/ext/nokogiri/xml_syntax_error.c +42 -21
  113. data/ext/nokogiri/xml_text.c +14 -18
  114. data/ext/nokogiri/xml_xpath_context.c +263 -148
  115. data/ext/nokogiri/xslt_stylesheet.c +271 -178
  116. data/gumbo-parser/CHANGES.md +63 -0
  117. data/gumbo-parser/Makefile +111 -0
  118. data/gumbo-parser/THANKS +27 -0
  119. data/lib/nokogiri/2.7/nokogiri.so +0 -0
  120. data/lib/nokogiri/3.0/nokogiri.so +0 -0
  121. data/lib/nokogiri/3.1/nokogiri.so +0 -0
  122. data/lib/nokogiri/3.2/nokogiri.so +0 -0
  123. data/lib/nokogiri/class_resolver.rb +67 -0
  124. data/lib/nokogiri/css/node.rb +10 -8
  125. data/lib/nokogiri/css/parser.rb +397 -377
  126. data/lib/nokogiri/css/parser.y +250 -245
  127. data/lib/nokogiri/css/parser_extras.rb +54 -49
  128. data/lib/nokogiri/css/syntax_error.rb +3 -1
  129. data/lib/nokogiri/css/tokenizer.rb +5 -3
  130. data/lib/nokogiri/css/tokenizer.rex +3 -2
  131. data/lib/nokogiri/css/xpath_visitor.rb +223 -94
  132. data/lib/nokogiri/css.rb +56 -17
  133. data/lib/nokogiri/decorators/slop.rb +9 -7
  134. data/lib/nokogiri/encoding_handler.rb +57 -0
  135. data/lib/nokogiri/extension.rb +32 -0
  136. data/lib/nokogiri/gumbo.rb +15 -0
  137. data/lib/nokogiri/html.rb +38 -27
  138. data/lib/nokogiri/{html → html4}/builder.rb +4 -2
  139. data/lib/nokogiri/html4/document.rb +214 -0
  140. data/lib/nokogiri/html4/document_fragment.rb +54 -0
  141. data/lib/nokogiri/{html → html4}/element_description.rb +3 -1
  142. data/lib/nokogiri/html4/element_description_defaults.rb +572 -0
  143. data/lib/nokogiri/html4/encoding_reader.rb +121 -0
  144. data/lib/nokogiri/{html → html4}/entity_lookup.rb +4 -2
  145. data/lib/nokogiri/{html → html4}/sax/parser.rb +17 -16
  146. data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
  147. data/lib/nokogiri/{html → html4}/sax/push_parser.rb +12 -11
  148. data/lib/nokogiri/html4.rb +47 -0
  149. data/lib/nokogiri/html5/document.rb +168 -0
  150. data/lib/nokogiri/html5/document_fragment.rb +90 -0
  151. data/lib/nokogiri/html5/node.rb +98 -0
  152. data/lib/nokogiri/html5.rb +389 -0
  153. data/lib/nokogiri/jruby/dependencies.rb +3 -0
  154. data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
  155. data/lib/nokogiri/syntax_error.rb +2 -0
  156. data/lib/nokogiri/version/constant.rb +6 -0
  157. data/lib/nokogiri/version/info.rb +223 -0
  158. data/lib/nokogiri/version.rb +3 -108
  159. data/lib/nokogiri/xml/attr.rb +55 -3
  160. data/lib/nokogiri/xml/attribute_decl.rb +3 -1
  161. data/lib/nokogiri/xml/builder.rb +75 -34
  162. data/lib/nokogiri/xml/cdata.rb +3 -1
  163. data/lib/nokogiri/xml/character_data.rb +2 -0
  164. data/lib/nokogiri/xml/document.rb +312 -126
  165. data/lib/nokogiri/xml/document_fragment.rb +93 -48
  166. data/lib/nokogiri/xml/dtd.rb +4 -2
  167. data/lib/nokogiri/xml/element_content.rb +2 -0
  168. data/lib/nokogiri/xml/element_decl.rb +3 -1
  169. data/lib/nokogiri/xml/entity_decl.rb +4 -2
  170. data/lib/nokogiri/xml/entity_reference.rb +2 -0
  171. data/lib/nokogiri/xml/namespace.rb +45 -0
  172. data/lib/nokogiri/xml/node/save_options.rb +15 -8
  173. data/lib/nokogiri/xml/node.rb +1067 -406
  174. data/lib/nokogiri/xml/node_set.rb +135 -59
  175. data/lib/nokogiri/xml/notation.rb +13 -0
  176. data/lib/nokogiri/xml/parse_options.rb +145 -52
  177. data/lib/nokogiri/xml/pp/character_data.rb +9 -6
  178. data/lib/nokogiri/xml/pp/node.rb +27 -26
  179. data/lib/nokogiri/xml/pp.rb +4 -2
  180. data/lib/nokogiri/xml/processing_instruction.rb +4 -1
  181. data/lib/nokogiri/xml/reader.rb +21 -28
  182. data/lib/nokogiri/xml/relax_ng.rb +8 -2
  183. data/lib/nokogiri/xml/sax/document.rb +45 -49
  184. data/lib/nokogiri/xml/sax/parser.rb +39 -36
  185. data/lib/nokogiri/xml/sax/parser_context.rb +8 -3
  186. data/lib/nokogiri/xml/sax/push_parser.rb +6 -5
  187. data/lib/nokogiri/xml/sax.rb +6 -4
  188. data/lib/nokogiri/xml/schema.rb +19 -9
  189. data/lib/nokogiri/xml/searchable.rb +112 -72
  190. data/lib/nokogiri/xml/syntax_error.rb +6 -4
  191. data/lib/nokogiri/xml/text.rb +2 -0
  192. data/lib/nokogiri/xml/xpath/syntax_error.rb +4 -2
  193. data/lib/nokogiri/xml/xpath.rb +15 -4
  194. data/lib/nokogiri/xml/xpath_context.rb +3 -3
  195. data/lib/nokogiri/xml.rb +38 -37
  196. data/lib/nokogiri/xslt/stylesheet.rb +3 -1
  197. data/lib/nokogiri/xslt.rb +29 -20
  198. data/lib/nokogiri.rb +48 -72
  199. data/lib/xsd/xmlparser/nokogiri.rb +29 -25
  200. metadata +146 -307
  201. data/ext/nokogiri/html_document.c +0 -170
  202. data/ext/nokogiri/html_document.h +0 -10
  203. data/ext/nokogiri/html_element_description.c +0 -279
  204. data/ext/nokogiri/html_element_description.h +0 -10
  205. data/ext/nokogiri/html_entity_lookup.c +0 -32
  206. data/ext/nokogiri/html_entity_lookup.h +0 -8
  207. data/ext/nokogiri/html_sax_parser_context.c +0 -116
  208. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  209. data/ext/nokogiri/html_sax_push_parser.c +0 -87
  210. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  211. data/ext/nokogiri/xml_attr.h +0 -9
  212. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  213. data/ext/nokogiri/xml_cdata.h +0 -9
  214. data/ext/nokogiri/xml_comment.h +0 -9
  215. data/ext/nokogiri/xml_document.h +0 -23
  216. data/ext/nokogiri/xml_document_fragment.h +0 -10
  217. data/ext/nokogiri/xml_dtd.h +0 -10
  218. data/ext/nokogiri/xml_element_content.h +0 -10
  219. data/ext/nokogiri/xml_element_decl.h +0 -9
  220. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  221. data/ext/nokogiri/xml_entity_decl.h +0 -10
  222. data/ext/nokogiri/xml_entity_reference.h +0 -9
  223. data/ext/nokogiri/xml_io.c +0 -61
  224. data/ext/nokogiri/xml_io.h +0 -11
  225. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  226. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  227. data/ext/nokogiri/xml_namespace.h +0 -14
  228. data/ext/nokogiri/xml_node.h +0 -13
  229. data/ext/nokogiri/xml_node_set.h +0 -12
  230. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  231. data/ext/nokogiri/xml_reader.h +0 -10
  232. data/ext/nokogiri/xml_relax_ng.h +0 -9
  233. data/ext/nokogiri/xml_sax_parser.h +0 -39
  234. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  235. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  236. data/ext/nokogiri/xml_schema.h +0 -9
  237. data/ext/nokogiri/xml_syntax_error.h +0 -13
  238. data/ext/nokogiri/xml_text.h +0 -9
  239. data/ext/nokogiri/xml_xpath_context.h +0 -10
  240. data/ext/nokogiri/xslt_stylesheet.h +0 -14
  241. data/lib/nokogiri/html/document.rb +0 -335
  242. data/lib/nokogiri/html/document_fragment.rb +0 -49
  243. data/lib/nokogiri/html/element_description_defaults.rb +0 -671
  244. data/lib/nokogiri/html/sax/parser_context.rb +0 -16
  245. data/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch +0 -78
  246. data/patches/libxml2/0002-Remove-script-macro-support.patch +0 -40
  247. data/patches/libxml2/0003-Update-entities-to-remove-handling-of-ssi.patch +0 -44
  248. data/patches/libxml2/0004-libxml2.la-is-in-top_builddir.patch +0 -25
  249. data/patches/libxml2/0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch +0 -32
  250. data/ports/archives/libxml2-2.9.10.tar.gz +0 -0
  251. data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
@@ -1,29 +1,127 @@
1
- #include <xml_xpath_context.h>
1
+ #include <nokogiri.h>
2
2
 
3
- int vasprintf (char **strp, const char *fmt, va_list ap);
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 deallocate(xmlXPathContextPtr ctx)
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 register_ns(VALUE self, VALUE prefix, VALUE uri)
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( ctx,
24
- (const xmlChar *)StringValueCStr(prefix),
25
- (const xmlChar *)StringValueCStr(uri)
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 register_variable(VALUE self, VALUE name, VALUE value)
134
+ static VALUE
135
+ rb_xml_xpath_context_register_variable(VALUE self, VALUE name, VALUE value)
37
136
  {
38
- xmlXPathContextPtr ctx;
39
- xmlXPathObjectPtr xmlValue;
40
- Data_Get_Struct(self, xmlXPathContext, ctx);
137
+ xmlXPathContextPtr ctx;
138
+ xmlXPathObjectPtr xmlValue;
139
+ Data_Get_Struct(self, xmlXPathContext, ctx);
41
140
 
42
- xmlValue = xmlXPathNewCString(StringValueCStr(value));
141
+ xmlValue = xmlXPathNewCString(StringValueCStr(value));
43
142
 
44
- xmlXPathRegisterVariable( ctx,
45
- (const xmlChar *)StringValueCStr(name),
46
- xmlValue
47
- );
143
+ xmlXPathRegisterVariable(ctx,
144
+ (const xmlChar *)StringValueCStr(name),
145
+ xmlValue
146
+ );
48
147
 
49
- return self;
148
+ return self;
50
149
  }
51
150
 
52
- void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler, const char* function_name)
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
- int i;
55
- VALUE result, doc;
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 node_set = Qnil;
58
- xmlNodeSetPtr xml_node_set = NULL;
59
- xmlXPathObjectPtr obj;
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 *)calloc((size_t)nargs, sizeof(VALUE));
65
- for (i = 0 ; i < nargs ; ++i) {
66
- rb_gc_register_address(&argv[i]);
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
- doc = DOC_RUBY_OBJECT(ctx->context->doc);
70
-
71
- if (nargs > 0) {
72
- i = nargs - 1;
73
- do {
74
- obj = valuePop(ctx);
75
- switch(obj->type) {
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
- result = rb_funcall2(handler, rb_intern((const char*)function_name), nargs, argv);
216
+ rb_retval = rb_funcall2(rb_xpath_handler, rb_intern((const char *)method_name), argc, argv);
96
217
 
97
- for (i = 0 ; i < nargs ; ++i) {
98
- rb_gc_unregister_address(&argv[i]);
218
+ for (int j = 0 ; j < argc ; ++j) {
219
+ rb_gc_unregister_address(&argv[j]);
99
220
  }
100
- free(argv);
221
+ ruby_xfree(argv);
101
222
 
102
- switch(TYPE(result)) {
223
+ switch (TYPE(rb_retval)) {
103
224
  case T_FLOAT:
104
225
  case T_BIGNUM:
105
226
  case T_FIXNUM:
106
- xmlXPathReturnNumber(ctx, NUM2DBL(result));
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
- VALUE args[2];
125
- args[0] = doc;
126
- args[1] = result;
127
- node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
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(result, cNokogiriXmlNodeSet)) {
134
- Data_Get_Struct(result, xmlNodeSet, xml_node_set);
248
+ if (rb_obj_is_kind_of(rb_retval, cNokogiriXmlNodeSet)) {
249
+ Data_Get_Struct(rb_retval, xmlNodeSet, c_node_set);
135
250
  /* Copy the node set, otherwise it will get GC'd. */
136
- xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
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 ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
259
+ static void
260
+ method_caller(xmlXPathParserContextPtr ctx, int argc)
145
261
  {
146
- VALUE handler = Qnil;
147
- const char *function = NULL ;
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
- handler = (VALUE)(ctx->context->userData);
155
- function = (const char*)(ctx->context->function);
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, nargs, handler, function);
273
+ Nokogiri_marshal_xpath_funcall_and_return_values(ctx, argc, rb_xpath_handler, method_name);
158
274
  }
159
275
 
160
- static xmlXPathFunction lookup( void *ctx,
161
- const xmlChar * name,
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 xpath_handler = (VALUE)ctx;
165
- if(rb_respond_to(xpath_handler, rb_intern((const char *)name)))
166
- return ruby_funcall;
279
+ VALUE rb_xpath_handler = (VALUE)ctx;
280
+ if (rb_respond_to(rb_xpath_handler, rb_intern((const char *)c_name))) {
281
+ return method_caller;
282
+ }
167
283
 
168
284
  return NULL;
169
285
  }
170
286
 
171
- NORETURN(static void xpath_generic_exception_handler(void * ctx, const char *msg, ...));
172
- static void xpath_generic_exception_handler(void * ctx, const char *msg, ...)
287
+ PRINTFLIKE_DECL(2, 3)
288
+ static void
289
+ generic_exception_pusher(void *ctx, const char *msg, ...)
173
290
  {
174
- char * message;
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
- vasprintf(&message, msg, args);
304
+ rb_message = rb_vsprintf(msg, args);
179
305
  va_end(args);
306
+ #endif
180
307
 
181
- rb_raise(rb_eRuntimeError, "%s", message);
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 evaluate(int argc, VALUE *argv, VALUE self)
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 thing = Qnil;
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, lookup, (void *)xpath_handler);
339
+ xmlXPathRegisterFuncLookup(ctx, handler_lookup, (void *)xpath_handler);
209
340
  }
210
341
 
211
- xmlResetLastError();
212
- xmlSetStructuredErrorFunc(NULL, Nokogiri_error_raise);
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
- xmlErrorPtr error = xmlGetLastError();
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
- assert(ctx->doc);
228
- assert(DOC_RUBY_OBJECT_TEST(ctx->doc));
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 thing;
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 new(VALUE klass, VALUE nodeobj)
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
- xmlXPathInit();
377
+ Noko_Node_Get_Struct(nodeobj, xmlNode, node);
267
378
 
268
- Data_Get_Struct(nodeobj, xmlNode, node);
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
- self = Data_Wrap_Struct(klass, 0, deallocate, ctx);
273
- /*rb_iv_set(self, "@xpath_handler", Qnil); */
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
- VALUE cNokogiriXmlXpathContext;
278
- void init_xml_xpath_context(void)
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
- VALUE klass = rb_define_class_under(xml, "XPathContext", rb_cObject);
404
+ cNokogiriXmlXpathContext = rb_define_class_under(mNokogiriXml, "XPathContext", rb_cObject);
405
+
406
+ rb_undef_alloc_func(cNokogiriXmlXpathContext);
291
407
 
292
- cNokogiriXmlXpathContext = klass;
408
+ rb_define_singleton_method(cNokogiriXmlXpathContext, "new", rb_xml_xpath_context_new, 1);
293
409
 
294
- rb_define_singleton_method(klass, "new", new, 1);
295
- rb_define_method(klass, "evaluate", evaluate, -1);
296
- rb_define_method(klass, "register_variable", register_variable, 2);
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
  }