nokogiri 1.11.0.rc3-x86-mingw32 → 1.11.0.rc4-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/LICENSE-DEPENDENCIES.md +1015 -947
- data/README.md +1 -1
- data/ext/nokogiri/depend +476 -357
- data/ext/nokogiri/extconf.rb +441 -321
- data/ext/nokogiri/html_document.c +79 -78
- data/ext/nokogiri/html_sax_parser_context.c +2 -2
- data/ext/nokogiri/include/libexslt/exslt.h +102 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +126 -0
- data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
- data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
- data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
- data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
- data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
- data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1241 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
- data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +366 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +945 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +153 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +566 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
- data/ext/nokogiri/include/libxslt/attributes.h +38 -0
- data/ext/nokogiri/include/libxslt/documents.h +93 -0
- data/ext/nokogiri/include/libxslt/extensions.h +262 -0
- data/ext/nokogiri/include/libxslt/extra.h +72 -0
- data/ext/nokogiri/include/libxslt/functions.h +78 -0
- data/ext/nokogiri/include/libxslt/imports.h +75 -0
- data/ext/nokogiri/include/libxslt/keys.h +53 -0
- data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
- data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
- data/ext/nokogiri/include/libxslt/pattern.h +84 -0
- data/ext/nokogiri/include/libxslt/preproc.h +43 -0
- data/ext/nokogiri/include/libxslt/security.h +104 -0
- data/ext/nokogiri/include/libxslt/templates.h +77 -0
- data/ext/nokogiri/include/libxslt/transform.h +207 -0
- data/ext/nokogiri/include/libxslt/variables.h +118 -0
- data/ext/nokogiri/include/libxslt/xslt.h +110 -0
- data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
- data/ext/nokogiri/nokogiri.c +34 -46
- data/ext/nokogiri/nokogiri.h +22 -26
- data/ext/nokogiri/xml_document.c +2 -2
- data/ext/nokogiri/xml_node.c +1 -1
- data/ext/nokogiri/xml_node_set.c +1 -1
- data/ext/nokogiri/xml_relax_ng.c +29 -11
- data/ext/nokogiri/xml_sax_parser.c +2 -7
- data/ext/nokogiri/xml_sax_parser_context.c +2 -2
- data/ext/nokogiri/xml_schema.c +55 -13
- data/ext/nokogiri/xml_xpath_context.c +80 -4
- data/ext/nokogiri/xslt_stylesheet.c +1 -4
- data/lib/nokogiri.rb +1 -1
- data/lib/nokogiri/2.5/nokogiri.so +0 -0
- data/lib/nokogiri/2.6/nokogiri.so +0 -0
- data/lib/nokogiri/2.7/nokogiri.so +0 -0
- data/lib/nokogiri/3.0/nokogiri.so +0 -0
- data/lib/nokogiri/css/parser.rb +3 -3
- data/lib/nokogiri/css/parser.y +2 -2
- data/lib/nokogiri/css/xpath_visitor.rb +70 -42
- data/lib/nokogiri/html/document.rb +12 -26
- data/lib/nokogiri/version.rb +2 -149
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +182 -0
- data/lib/nokogiri/xml/document.rb +17 -7
- data/lib/nokogiri/xml/document_fragment.rb +4 -6
- data/lib/nokogiri/xml/node.rb +50 -27
- data/lib/nokogiri/xml/parse_options.rb +6 -0
- data/lib/nokogiri/xml/relax_ng.rb +6 -2
- data/lib/nokogiri/xml/schema.rb +12 -4
- data/lib/nokogiri/xml/searchable.rb +3 -1
- metadata +105 -28
- data/lib/nokogiri/2.4/nokogiri.so +0 -0
data/ext/nokogiri/nokogiri.c
CHANGED
@@ -7,12 +7,11 @@ VALUE mNokogiriXslt ;
|
|
7
7
|
VALUE mNokogiriXmlSax ;
|
8
8
|
VALUE mNokogiriHtmlSax ;
|
9
9
|
|
10
|
-
#
|
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
|
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
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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(
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
rb_const_set(
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
rb_const_set(
|
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("
|
103
|
-
rb_const_set(mNokogiri, rb_intern("
|
104
|
-
rb_const_set(mNokogiri, rb_intern("
|
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();
|
data/ext/nokogiri/nokogiri.h
CHANGED
@@ -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
|
-
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
#include <
|
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
|
-
#
|
126
|
-
#
|
127
|
-
#
|
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"
|
data/ext/nokogiri/xml_document.c
CHANGED
@@ -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
|
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",
|
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);
|
data/ext/nokogiri/xml_node.c
CHANGED
@@ -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
|
}
|
data/ext/nokogiri/xml_node_set.c
CHANGED
data/ext/nokogiri/xml_relax_ng.c
CHANGED
@@ -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
|
56
|
+
static VALUE read_memory(int argc, VALUE *argv, VALUE klass)
|
57
57
|
{
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
);
|
58
|
+
VALUE content;
|
59
|
+
VALUE parse_options;
|
60
|
+
xmlRelaxNGParserCtxtPtr ctx;
|
62
61
|
xmlRelaxNGPtr schema;
|
63
|
-
VALUE errors
|
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
|
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
|
-
|
114
|
-
|
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
|
-
|
206
|
+
free(message);
|
210
207
|
rb_funcall(doc, id_warning, 1, ruby_message);
|
211
208
|
}
|
212
209
|
|
@@ -223,7 +220,7 @@ static void error_func(void * ctx, const char *msg, ...)
|
|
223
220
|
va_end(args);
|
224
221
|
|
225
222
|
ruby_message = NOKOGIRI_STR_NEW2(message);
|
226
|
-
|
223
|
+
free(message);
|
227
224
|
rb_funcall(doc, id_error, 1, ruby_message);
|
228
225
|
}
|
229
226
|
|
@@ -262,8 +259,6 @@ static VALUE allocate(VALUE klass)
|
|
262
259
|
{
|
263
260
|
xmlSAXHandlerPtr handler = calloc((size_t)1, sizeof(xmlSAXHandler));
|
264
261
|
|
265
|
-
xmlSetStructuredErrorFunc(NULL, NULL);
|
266
|
-
|
267
262
|
handler->startDocument = start_document;
|
268
263
|
handler->endDocument = end_document;
|
269
264
|
handler->startElement = start_element;
|
@@ -4,13 +4,13 @@ VALUE cNokogiriXmlSaxParserContext ;
|
|
4
4
|
|
5
5
|
static void deallocate(xmlParserCtxtPtr ctxt)
|
6
6
|
{
|
7
|
-
NOKOGIRI_DEBUG_START(
|
7
|
+
NOKOGIRI_DEBUG_START(ctxt);
|
8
8
|
|
9
9
|
ctxt->sax = NULL;
|
10
10
|
|
11
11
|
xmlFreeParserCtxt(ctxt);
|
12
12
|
|
13
|
-
NOKOGIRI_DEBUG_END(
|
13
|
+
NOKOGIRI_DEBUG_END(ctxt);
|
14
14
|
}
|
15
15
|
|
16
16
|
/*
|
data/ext/nokogiri/xml_schema.c
CHANGED
@@ -93,15 +93,27 @@ static VALUE validate_file(VALUE self, VALUE rb_filename)
|
|
93
93
|
*
|
94
94
|
* Create a new Schema from the contents of +string+
|
95
95
|
*/
|
96
|
-
static VALUE read_memory(VALUE
|
96
|
+
static VALUE read_memory(int argc, VALUE *argv, VALUE klass)
|
97
97
|
{
|
98
|
+
VALUE content;
|
99
|
+
VALUE parse_options;
|
100
|
+
int parse_options_int;
|
101
|
+
xmlSchemaParserCtxtPtr ctx;
|
98
102
|
xmlSchemaPtr schema;
|
99
|
-
|
100
|
-
(const char *)StringValuePtr(content),
|
101
|
-
(int)RSTRING_LEN(content)
|
102
|
-
);
|
103
|
+
VALUE errors;
|
103
104
|
VALUE rb_schema;
|
104
|
-
|
105
|
+
int scanned_args = 0;
|
106
|
+
xmlExternalEntityLoader old_loader = 0;
|
107
|
+
|
108
|
+
scanned_args = rb_scan_args(argc, argv, "11", &content, &parse_options);
|
109
|
+
if (scanned_args == 1) {
|
110
|
+
parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
111
|
+
}
|
112
|
+
parse_options_int = (int)NUM2INT(rb_funcall(parse_options, rb_intern("to_i"), 0));
|
113
|
+
|
114
|
+
ctx = xmlSchemaNewMemParserCtxt((const char *)StringValuePtr(content), (int)RSTRING_LEN(content));
|
115
|
+
|
116
|
+
errors = rb_ary_new();
|
105
117
|
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
106
118
|
|
107
119
|
#ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
|
@@ -109,10 +121,19 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
109
121
|
ctx,
|
110
122
|
Nokogiri_error_array_pusher,
|
111
123
|
(void *)errors
|
112
|
-
|
124
|
+
);
|
113
125
|
#endif
|
114
126
|
|
115
|
-
|
127
|
+
if (parse_options_int & XML_PARSE_NONET) {
|
128
|
+
old_loader = xmlGetExternalEntityLoader();
|
129
|
+
xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
|
130
|
+
}
|
131
|
+
|
132
|
+
schema = xmlSchemaParse(ctx);
|
133
|
+
|
134
|
+
if (old_loader) {
|
135
|
+
xmlSetExternalEntityLoader(old_loader);
|
136
|
+
}
|
116
137
|
|
117
138
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
118
139
|
xmlSchemaFreeParserCtxt(ctx);
|
@@ -129,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
|
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
|
-
|
178
|
-
|
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);
|