nokogiri 1.11.0.rc3-x64-mingw32 → 1.11.0.rc4-x64-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.

Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +1015 -947
  3. data/README.md +1 -1
  4. data/ext/nokogiri/depend +476 -357
  5. data/ext/nokogiri/extconf.rb +441 -321
  6. data/ext/nokogiri/html_document.c +79 -78
  7. data/ext/nokogiri/html_sax_parser_context.c +2 -2
  8. data/ext/nokogiri/include/libexslt/exslt.h +102 -0
  9. data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
  10. data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
  11. data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
  12. data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
  13. data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
  14. data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
  15. data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
  16. data/ext/nokogiri/include/libxml2/libxml/c14n.h +126 -0
  17. data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
  18. data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
  19. data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
  20. data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
  21. data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
  22. data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
  23. data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
  24. data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
  25. data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
  26. data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
  27. data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
  28. data/ext/nokogiri/include/libxml2/libxml/parser.h +1241 -0
  29. data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
  30. data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
  31. data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
  32. data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
  33. data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
  34. data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
  35. data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
  36. data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
  37. data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
  38. data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
  39. data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
  40. data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +366 -0
  41. data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
  42. data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +945 -0
  43. data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +153 -0
  44. data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
  45. data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
  46. data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
  47. data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
  48. data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
  49. data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
  50. data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
  51. data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
  52. data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
  53. data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
  54. data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
  55. data/ext/nokogiri/include/libxml2/libxml/xpath.h +566 -0
  56. data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
  57. data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
  58. data/ext/nokogiri/include/libxslt/attributes.h +38 -0
  59. data/ext/nokogiri/include/libxslt/documents.h +93 -0
  60. data/ext/nokogiri/include/libxslt/extensions.h +262 -0
  61. data/ext/nokogiri/include/libxslt/extra.h +72 -0
  62. data/ext/nokogiri/include/libxslt/functions.h +78 -0
  63. data/ext/nokogiri/include/libxslt/imports.h +75 -0
  64. data/ext/nokogiri/include/libxslt/keys.h +53 -0
  65. data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
  66. data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
  67. data/ext/nokogiri/include/libxslt/pattern.h +84 -0
  68. data/ext/nokogiri/include/libxslt/preproc.h +43 -0
  69. data/ext/nokogiri/include/libxslt/security.h +104 -0
  70. data/ext/nokogiri/include/libxslt/templates.h +77 -0
  71. data/ext/nokogiri/include/libxslt/transform.h +207 -0
  72. data/ext/nokogiri/include/libxslt/variables.h +118 -0
  73. data/ext/nokogiri/include/libxslt/xslt.h +110 -0
  74. data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
  75. data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
  76. data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
  77. data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
  78. data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
  79. data/ext/nokogiri/nokogiri.c +34 -46
  80. data/ext/nokogiri/nokogiri.h +22 -26
  81. data/ext/nokogiri/xml_document.c +2 -2
  82. data/ext/nokogiri/xml_node.c +1 -1
  83. data/ext/nokogiri/xml_node_set.c +1 -1
  84. data/ext/nokogiri/xml_relax_ng.c +29 -11
  85. data/ext/nokogiri/xml_sax_parser.c +2 -7
  86. data/ext/nokogiri/xml_sax_parser_context.c +2 -2
  87. data/ext/nokogiri/xml_schema.c +55 -13
  88. data/ext/nokogiri/xml_xpath_context.c +80 -4
  89. data/ext/nokogiri/xslt_stylesheet.c +1 -4
  90. data/lib/nokogiri.rb +1 -1
  91. data/lib/nokogiri/2.5/nokogiri.so +0 -0
  92. data/lib/nokogiri/2.6/nokogiri.so +0 -0
  93. data/lib/nokogiri/2.7/nokogiri.so +0 -0
  94. data/lib/nokogiri/3.0/nokogiri.so +0 -0
  95. data/lib/nokogiri/css/parser.rb +3 -3
  96. data/lib/nokogiri/css/parser.y +2 -2
  97. data/lib/nokogiri/css/xpath_visitor.rb +70 -42
  98. data/lib/nokogiri/html/document.rb +12 -26
  99. data/lib/nokogiri/version.rb +2 -149
  100. data/lib/nokogiri/version/constant.rb +5 -0
  101. data/lib/nokogiri/version/info.rb +182 -0
  102. data/lib/nokogiri/xml/document.rb +17 -7
  103. data/lib/nokogiri/xml/document_fragment.rb +4 -6
  104. data/lib/nokogiri/xml/node.rb +50 -27
  105. data/lib/nokogiri/xml/parse_options.rb +6 -0
  106. data/lib/nokogiri/xml/relax_ng.rb +6 -2
  107. data/lib/nokogiri/xml/schema.rb +12 -4
  108. data/lib/nokogiri/xml/searchable.rb +3 -1
  109. metadata +105 -28
  110. data/lib/nokogiri/2.4/nokogiri.so +0 -0
@@ -7,12 +7,11 @@ VALUE mNokogiriXslt ;
7
7
  VALUE mNokogiriXmlSax ;
8
8
  VALUE mNokogiriHtmlSax ;
9
9
 
10
- #ifdef USE_INCLUDED_VASPRINTF
10
+ #ifndef HAVE_VASPRINTF
11
11
  /*
12
- * I srsly hate windows. it doesn't have vasprintf.
13
12
  * Thank you Geoffroy Couprie for this implementation of vasprintf!
14
13
  */
15
- int vasprintf (char **strp, const char *fmt, va_list ap)
14
+ int vasprintf(char **strp, const char *fmt, va_list ap)
16
15
  {
17
16
  /* Mingw32/64 have a broken vsnprintf implementation that fails when
18
17
  * using a zero-byte limit in order to retrieve the required size for malloc.
@@ -21,23 +20,15 @@ int vasprintf (char **strp, const char *fmt, va_list ap)
21
20
  char tmp[1];
22
21
  int len = vsnprintf (tmp, 1, fmt, ap) + 1;
23
22
  char *res = (char *)malloc((unsigned int)len);
24
- if (res == NULL)
25
- return -1;
23
+ if (res == NULL) {
24
+ return -1;
25
+ }
26
26
  *strp = res;
27
27
  return vsnprintf(res, (unsigned int)len, fmt, ap);
28
28
  }
29
29
  #endif
30
30
 
31
- void vasprintf_free (void *p)
32
- {
33
- free(p);
34
- }
35
-
36
- #ifdef HAVE_RUBY_UTIL_H
37
31
  #include "ruby/util.h"
38
- #else
39
- #include "util.h"
40
- #endif
41
32
 
42
33
  void nokogiri_root_node(xmlNodePtr node)
43
34
  {
@@ -45,7 +36,7 @@ void nokogiri_root_node(xmlNodePtr node)
45
36
  nokogiriTuplePtr tuple;
46
37
 
47
38
  doc = node->doc;
48
- if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
39
+ if (doc->type == XML_DOCUMENT_FRAG_NODE) { doc = doc->doc; }
49
40
  tuple = (nokogiriTuplePtr)doc->_private;
50
41
  st_insert(tuple->unlinkedNodes, (st_data_t)node, (st_data_t)node);
51
42
  }
@@ -54,7 +45,7 @@ void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
54
45
  {
55
46
  nokogiriTuplePtr tuple;
56
47
 
57
- if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
48
+ if (doc->type == XML_DOCUMENT_FRAG_NODE) { doc = doc->doc; }
58
49
  tuple = (nokogiriTuplePtr)doc->_private;
59
50
  st_insert(tuple->unlinkedNodes, (st_data_t)ns, (st_data_t)ns);
60
51
  }
@@ -62,10 +53,10 @@ void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
62
53
  void Init_nokogiri()
63
54
  {
64
55
  xmlMemSetup(
65
- (xmlFreeFunc)ruby_xfree,
66
- (xmlMallocFunc)ruby_xmalloc,
67
- (xmlReallocFunc)ruby_xrealloc,
68
- ruby_strdup
56
+ (xmlFreeFunc)ruby_xfree,
57
+ (xmlMallocFunc)ruby_xmalloc,
58
+ (xmlReallocFunc)ruby_xrealloc,
59
+ ruby_strdup
69
60
  );
70
61
 
71
62
  mNokogiri = rb_define_module("Nokogiri");
@@ -75,33 +66,26 @@ void Init_nokogiri()
75
66
  mNokogiriXmlSax = rb_define_module_under(mNokogiriXml, "SAX");
76
67
  mNokogiriHtmlSax = rb_define_module_under(mNokogiriHtml, "SAX");
77
68
 
78
- rb_const_set( mNokogiri,
79
- rb_intern("LIBXML_COMPILED_VERSION"),
80
- NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION)
81
- );
82
- rb_const_set( mNokogiri,
83
- rb_intern("LIBXML_LOADED_VERSION"),
84
- NOKOGIRI_STR_NEW2(xmlParserVersion)
85
- );
86
-
87
-
88
- rb_const_set( mNokogiri,
89
- rb_intern("LIBXSLT_COMPILED_VERSION"),
90
- NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION)
91
- );
92
- rb_const_set( mNokogiri,
93
- rb_intern("LIBXSLT_LOADED_VERSION"),
94
- NOKOGIRI_STR_NEW2(xsltEngineVersion)
95
- );
96
-
97
- #ifdef NOKOGIRI_USE_PACKAGED_LIBRARIES
98
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qtrue);
99
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
100
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
69
+ rb_const_set(mNokogiri, rb_intern("LIBXML_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION));
70
+ rb_const_set(mNokogiri, rb_intern("LIBXML_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xmlParserVersion));
71
+
72
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION));
73
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xsltEngineVersion));
74
+
75
+ #ifdef NOKOGIRI_PACKAGED_LIBRARIES
76
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
77
+ #ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
78
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qtrue);
79
+ #else
80
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
81
+ #endif
82
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
83
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
101
84
  #else
102
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qfalse);
103
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATCHES"), Qnil);
104
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATCHES"), Qnil);
85
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qfalse);
86
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
87
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), Qnil);
88
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), Qnil);
105
89
  #endif
106
90
 
107
91
  #ifdef LIBXML_ICONV_ENABLED
@@ -110,6 +94,10 @@ void Init_nokogiri()
110
94
  rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse);
111
95
  #endif
112
96
 
97
+ #ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS
98
+ rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
99
+ #endif
100
+
113
101
  xmlInitParser();
114
102
 
115
103
  init_xml_document();
@@ -2,31 +2,24 @@
2
2
  #define NOKOGIRI_NATIVE
3
3
 
4
4
  #if _MSC_VER
5
- #ifndef WIN32_LEAN_AND_MEAN
6
- #define WIN32_LEAN_AND_MEAN
7
- #endif /* WIN32_LEAN_AND_MEAN */
8
- #ifndef WIN32
9
- #define WIN32
10
- #endif /* WIN32 */
11
- #include <winsock2.h>
12
- #include <ws2tcpip.h>
13
- #include <windows.h>
5
+ # ifndef WIN32_LEAN_AND_MEAN
6
+ # define WIN32_LEAN_AND_MEAN
7
+ # endif /* WIN32_LEAN_AND_MEAN */
8
+
9
+ # ifndef WIN32
10
+ # define WIN32
11
+ # endif /* WIN32 */
12
+
13
+ # include <winsock2.h>
14
+ # include <ws2tcpip.h>
15
+ # include <windows.h>
14
16
  #endif
15
17
 
16
18
  #include <stdlib.h>
17
19
  #include <string.h>
18
20
  #include <assert.h>
19
21
  #include <stdarg.h>
20
-
21
- #ifdef USE_INCLUDED_VASPRINTF
22
- int vasprintf (char **strp, const char *fmt, va_list ap);
23
- #else
24
-
25
- #define _GNU_SOURCE
26
- # include <stdio.h>
27
- #undef _GNU_SOURCE
28
-
29
- #endif
22
+ #include <stdio.h>
30
23
 
31
24
  #include <libxml/parser.h>
32
25
  #include <libxml/entities.h>
@@ -43,6 +36,7 @@ int vasprintf (char **strp, const char *fmt, va_list ap);
43
36
  #include <libxslt/extensions.h>
44
37
  #include <libxslt/xsltconfig.h>
45
38
  #include <libxml/c14n.h>
39
+
46
40
  #include <ruby.h>
47
41
  #include <ruby/st.h>
48
42
  #include <ruby/encoding.h>
@@ -106,25 +100,27 @@ extern VALUE mNokogiriHtml ;
106
100
  extern VALUE mNokogiriHtmlSax ;
107
101
  extern VALUE mNokogiriXslt ;
108
102
 
103
+ int vasprintf(char **strp, const char *fmt, va_list ap);
104
+
109
105
  void nokogiri_root_node(xmlNodePtr);
110
106
  void nokogiri_root_nsdef(xmlNsPtr, xmlDocPtr);
111
107
 
112
108
  #ifdef DEBUG
113
109
 
114
- #define NOKOGIRI_DEBUG_START(p) if (getenv("NOKOGIRI_NO_FREE")) return ; if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p start\n", __FILE__, __LINE__, p);
115
- #define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
110
+ # define NOKOGIRI_DEBUG_START(p) if (getenv("NOKOGIRI_NO_FREE")) return ; if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p start\n", __FILE__, __LINE__, p);
111
+ # define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
116
112
 
117
113
  #else
118
114
 
119
- #define NOKOGIRI_DEBUG_START(p)
120
- #define NOKOGIRI_DEBUG_END(p)
115
+ # define NOKOGIRI_DEBUG_START(p)
116
+ # define NOKOGIRI_DEBUG_END(p)
121
117
 
122
118
  #endif
123
119
 
124
120
  #ifndef __builtin_expect
125
- # if defined(__GNUC__)
126
- # define __builtin_expect(expr, c) __builtin_expect((long)(expr), (long)(c))
127
- # endif
121
+ # if defined(__GNUC__)
122
+ # define __builtin_expect(expr, c) __builtin_expect((long)(expr), (long)(c))
123
+ # endif
128
124
  #endif
129
125
 
130
126
  #define XMLNS_PREFIX "xmlns"
@@ -506,7 +506,7 @@ static int block_caller(void * ctx, xmlNodePtr _node, xmlNodePtr _parent)
506
506
  * The block must return a non-nil, non-false value if the +obj+ passed in
507
507
  * should be included in the canonicalized document.
508
508
  */
509
- static VALUE canonicalize(int argc, VALUE* argv, VALUE self)
509
+ static VALUE nokogiri_xml_document_canonicalize(int argc, VALUE* argv, VALUE self)
510
510
  {
511
511
  VALUE mode;
512
512
  VALUE incl_ns;
@@ -587,7 +587,7 @@ void init_xml_document()
587
587
  rb_define_method(klass, "encoding", encoding, 0);
588
588
  rb_define_method(klass, "encoding=", set_encoding, 1);
589
589
  rb_define_method(klass, "version", version, 0);
590
- rb_define_method(klass, "canonicalize", canonicalize, -1);
590
+ rb_define_method(klass, "canonicalize", nokogiri_xml_document_canonicalize, -1);
591
591
  rb_define_method(klass, "dup", duplicate_document, -1);
592
592
  rb_define_method(klass, "url", url, 0);
593
593
  rb_define_method(klass, "create_entity", create_entity, -1);
@@ -301,7 +301,7 @@ ok:
301
301
  * issue #391, where new node's prefix may become the string "default"
302
302
  * see libxml2 tree.c xmlNewReconciliedNs which implements this behavior.
303
303
  */
304
- xmlFree(reparentee->ns->prefix);
304
+ xmlFree((xmlChar*)reparentee->ns->prefix);
305
305
  reparentee->ns->prefix = NULL;
306
306
  }
307
307
  }
@@ -319,7 +319,7 @@ static VALUE slice(int argc, VALUE *argv, VALUE self)
319
319
  *
320
320
  * Return this list as an Array
321
321
  */
322
- static VALUE to_array(VALUE self, VALUE rb_node)
322
+ static VALUE to_array(VALUE self)
323
323
  {
324
324
  xmlNodeSetPtr node_set ;
325
325
  VALUE list;
@@ -53,16 +53,24 @@ static VALUE validate_document(VALUE self, VALUE document)
53
53
  *
54
54
  * Create a new RelaxNG from the contents of +string+
55
55
  */
56
- static VALUE read_memory(VALUE klass, VALUE content)
56
+ static VALUE read_memory(int argc, VALUE *argv, VALUE klass)
57
57
  {
58
- xmlRelaxNGParserCtxtPtr ctx = xmlRelaxNGNewMemParserCtxt(
59
- (const char *)StringValuePtr(content),
60
- (int)RSTRING_LEN(content)
61
- );
58
+ VALUE content;
59
+ VALUE parse_options;
60
+ xmlRelaxNGParserCtxtPtr ctx;
62
61
  xmlRelaxNGPtr schema;
63
- VALUE errors = rb_ary_new();
62
+ VALUE errors;
64
63
  VALUE rb_schema;
64
+ int scanned_args = 0;
65
+
66
+ scanned_args = rb_scan_args(argc, argv, "11", &content, &parse_options);
67
+ if (scanned_args == 1) {
68
+ parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
69
+ }
65
70
 
71
+ ctx = xmlRelaxNGNewMemParserCtxt((const char *)StringValuePtr(content), (int)RSTRING_LEN(content));
72
+
73
+ errors = rb_ary_new();
66
74
  xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
67
75
 
68
76
  #ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
@@ -90,6 +98,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
90
98
 
91
99
  rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
92
100
  rb_iv_set(rb_schema, "@errors", errors);
101
+ rb_iv_set(rb_schema, "@parse_options", parse_options);
93
102
 
94
103
  return rb_schema;
95
104
  }
@@ -100,18 +109,25 @@ static VALUE read_memory(VALUE klass, VALUE content)
100
109
  *
101
110
  * Create a new RelaxNG schema from the Nokogiri::XML::Document +doc+
102
111
  */
103
- static VALUE from_document(VALUE klass, VALUE document)
112
+ static VALUE from_document(int argc, VALUE *argv, VALUE klass)
104
113
  {
114
+ VALUE document;
115
+ VALUE parse_options;
105
116
  xmlDocPtr doc;
106
117
  xmlRelaxNGParserCtxtPtr ctx;
107
118
  xmlRelaxNGPtr schema;
108
119
  VALUE errors;
109
120
  VALUE rb_schema;
121
+ int scanned_args = 0;
122
+
123
+ scanned_args = rb_scan_args(argc, argv, "11", &document, &parse_options);
110
124
 
111
125
  Data_Get_Struct(document, xmlDoc, doc);
126
+ doc = doc->doc; /* In case someone passes us a node. ugh. */
112
127
 
113
- /* In case someone passes us a node. ugh. */
114
- doc = doc->doc;
128
+ if (scanned_args == 1) {
129
+ parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
130
+ }
115
131
 
116
132
  ctx = xmlRelaxNGNewDocParserCtxt(doc);
117
133
 
@@ -129,6 +145,7 @@ static VALUE from_document(VALUE klass, VALUE document)
129
145
  schema = xmlRelaxNGParse(ctx);
130
146
 
131
147
  xmlSetStructuredErrorFunc(NULL, NULL);
148
+ xmlRelaxNGFreeParserCtxt(ctx);
132
149
 
133
150
  if(NULL == schema) {
134
151
  xmlErrorPtr error = xmlGetLastError();
@@ -142,6 +159,7 @@ static VALUE from_document(VALUE klass, VALUE document)
142
159
 
143
160
  rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
144
161
  rb_iv_set(rb_schema, "@errors", errors);
162
+ rb_iv_set(rb_schema, "@parse_options", parse_options);
145
163
 
146
164
  return rb_schema;
147
165
  }
@@ -155,7 +173,7 @@ void init_xml_relax_ng()
155
173
 
156
174
  cNokogiriXmlRelaxNG = klass;
157
175
 
158
- rb_define_singleton_method(klass, "read_memory", read_memory, 1);
159
- rb_define_singleton_method(klass, "from_document", from_document, 1);
176
+ rb_define_singleton_method(klass, "read_memory", read_memory, -1);
177
+ rb_define_singleton_method(klass, "from_document", from_document, -1);
160
178
  rb_define_private_method(klass, "validate_document", validate_document, 1);
161
179
  }
@@ -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
- vasprintf_free(message);
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
- vasprintf_free(message);
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(handler);
7
+ NOKOGIRI_DEBUG_START(ctxt);
8
8
 
9
9
  ctxt->sax = NULL;
10
10
 
11
11
  xmlFreeParserCtxt(ctxt);
12
12
 
13
- NOKOGIRI_DEBUG_END(handler);
13
+ NOKOGIRI_DEBUG_END(ctxt);
14
14
  }
15
15
 
16
16
  /*
@@ -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 klass, VALUE content)
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
- xmlSchemaParserCtxtPtr ctx = xmlSchemaNewMemParserCtxt(
100
- (const char *)StringValuePtr(content),
101
- (int)RSTRING_LEN(content)
102
- );
103
+ VALUE errors;
103
104
  VALUE rb_schema;
104
- VALUE errors = rb_ary_new();
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
- schema = xmlSchemaParse(ctx);
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,6 +150,7 @@ 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
  }
@@ -164,18 +186,28 @@ static int has_blank_nodes_p(VALUE cache)
164
186
  *
165
187
  * Create a new Schema from the Nokogiri::XML::Document +doc+
166
188
  */
167
- static VALUE from_document(VALUE klass, VALUE document)
189
+ static VALUE from_document(int argc, VALUE *argv, VALUE klass)
168
190
  {
191
+ VALUE document;
192
+ VALUE parse_options;
193
+ int parse_options_int;
169
194
  xmlDocPtr doc;
170
195
  xmlSchemaParserCtxtPtr ctx;
171
196
  xmlSchemaPtr schema;
172
197
  VALUE errors;
173
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);
174
203
 
175
204
  Data_Get_Struct(document, xmlDoc, doc);
205
+ doc = doc->doc; /* In case someone passes us a node. ugh. */
176
206
 
177
- /* In case someone passes us a node. ugh. */
178
- doc = doc->doc;
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));
179
211
 
180
212
  if (has_blank_nodes_p(DOC_NODE_CACHE(doc))) {
181
213
  rb_raise(rb_eArgError, "Creating a schema from a document that has blank nodes exposed to Ruby is dangerous");
@@ -194,8 +226,17 @@ static VALUE from_document(VALUE klass, VALUE document)
194
226
  );
195
227
  #endif
196
228
 
229
+ if (parse_options_int & XML_PARSE_NONET) {
230
+ old_loader = xmlGetExternalEntityLoader();
231
+ xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
232
+ }
233
+
197
234
  schema = xmlSchemaParse(ctx);
198
235
 
236
+ if (old_loader) {
237
+ xmlSetExternalEntityLoader(old_loader);
238
+ }
239
+
199
240
  xmlSetStructuredErrorFunc(NULL, NULL);
200
241
  xmlSchemaFreeParserCtxt(ctx);
201
242
 
@@ -211,6 +252,7 @@ static VALUE from_document(VALUE klass, VALUE document)
211
252
 
212
253
  rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
213
254
  rb_iv_set(rb_schema, "@errors", errors);
255
+ rb_iv_set(rb_schema, "@parse_options", parse_options);
214
256
 
215
257
  return rb_schema;
216
258
 
@@ -226,8 +268,8 @@ void init_xml_schema()
226
268
 
227
269
  cNokogiriXmlSchema = klass;
228
270
 
229
- rb_define_singleton_method(klass, "read_memory", read_memory, 1);
230
- 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);
231
273
 
232
274
  rb_define_private_method(klass, "validate_document", validate_document, 1);
233
275
  rb_define_private_method(klass, "validate_file", validate_file, 1);