nokogiri 1.11.0.rc1-x86-linux → 1.11.1-x86-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 +3 -0
- data/LICENSE-DEPENDENCIES.md +1015 -947
- data/README.md +164 -92
- data/ext/nokogiri/depend +476 -357
- data/ext/nokogiri/extconf.rb +467 -326
- data/ext/nokogiri/html_document.c +79 -78
- data/ext/nokogiri/html_sax_parser_context.c +4 -2
- data/ext/nokogiri/html_sax_push_parser.c +14 -8
- 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 +37 -46
- data/ext/nokogiri/nokogiri.h +25 -17
- data/ext/nokogiri/test_global_handlers.c +41 -0
- data/ext/nokogiri/xml_document.c +8 -3
- data/ext/nokogiri/xml_io.c +8 -6
- data/ext/nokogiri/xml_node.c +1 -1
- data/ext/nokogiri/xml_node_set.c +1 -1
- data/ext/nokogiri/xml_reader.c +6 -17
- 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 +4 -2
- data/ext/nokogiri/xml_sax_push_parser.c +2 -0
- data/ext/nokogiri/xml_schema.c +84 -13
- data/ext/nokogiri/xml_syntax_error.c +23 -0
- data/ext/nokogiri/xml_syntax_error.h +15 -3
- data/ext/nokogiri/xml_xpath_context.c +80 -4
- data/ext/nokogiri/xslt_stylesheet.c +1 -4
- data/lib/nokogiri.rb +20 -3
- 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 +62 -62
- data/lib/nokogiri/css/parser.y +2 -2
- data/lib/nokogiri/css/parser_extras.rb +38 -36
- data/lib/nokogiri/css/xpath_visitor.rb +70 -42
- data/lib/nokogiri/html/document.rb +12 -26
- data/lib/nokogiri/version.rb +2 -148
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +182 -0
- data/lib/nokogiri/xml/builder.rb +2 -2
- data/lib/nokogiri/xml/document.rb +17 -7
- data/lib/nokogiri/xml/document_fragment.rb +4 -6
- data/lib/nokogiri/xml/node.rb +562 -238
- 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 +24 -16
- metadata +149 -130
- data/lib/nokogiri/2.4/nokogiri.so +0 -0
data/ext/nokogiri/nokogiri.c
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#include <nokogiri.h>
|
2
2
|
|
3
|
+
void init_test_global_handlers(); /* in lieu of test_global_handlers.h */
|
4
|
+
|
3
5
|
VALUE mNokogiri ;
|
4
6
|
VALUE mNokogiriXml ;
|
5
7
|
VALUE mNokogiriHtml ;
|
@@ -7,12 +9,11 @@ VALUE mNokogiriXslt ;
|
|
7
9
|
VALUE mNokogiriXmlSax ;
|
8
10
|
VALUE mNokogiriHtmlSax ;
|
9
11
|
|
10
|
-
#
|
12
|
+
#ifndef HAVE_VASPRINTF
|
11
13
|
/*
|
12
|
-
* I srsly hate windows. it doesn't have vasprintf.
|
13
14
|
* Thank you Geoffroy Couprie for this implementation of vasprintf!
|
14
15
|
*/
|
15
|
-
int vasprintf
|
16
|
+
int vasprintf(char **strp, const char *fmt, va_list ap)
|
16
17
|
{
|
17
18
|
/* Mingw32/64 have a broken vsnprintf implementation that fails when
|
18
19
|
* using a zero-byte limit in order to retrieve the required size for malloc.
|
@@ -21,23 +22,15 @@ int vasprintf (char **strp, const char *fmt, va_list ap)
|
|
21
22
|
char tmp[1];
|
22
23
|
int len = vsnprintf (tmp, 1, fmt, ap) + 1;
|
23
24
|
char *res = (char *)malloc((unsigned int)len);
|
24
|
-
if (res == NULL)
|
25
|
-
|
25
|
+
if (res == NULL) {
|
26
|
+
return -1;
|
27
|
+
}
|
26
28
|
*strp = res;
|
27
29
|
return vsnprintf(res, (unsigned int)len, fmt, ap);
|
28
30
|
}
|
29
31
|
#endif
|
30
32
|
|
31
|
-
void vasprintf_free (void *p)
|
32
|
-
{
|
33
|
-
free(p);
|
34
|
-
}
|
35
|
-
|
36
|
-
#ifdef HAVE_RUBY_UTIL_H
|
37
33
|
#include "ruby/util.h"
|
38
|
-
#else
|
39
|
-
#include "util.h"
|
40
|
-
#endif
|
41
34
|
|
42
35
|
void nokogiri_root_node(xmlNodePtr node)
|
43
36
|
{
|
@@ -45,7 +38,7 @@ void nokogiri_root_node(xmlNodePtr node)
|
|
45
38
|
nokogiriTuplePtr tuple;
|
46
39
|
|
47
40
|
doc = node->doc;
|
48
|
-
if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
|
41
|
+
if (doc->type == XML_DOCUMENT_FRAG_NODE) { doc = doc->doc; }
|
49
42
|
tuple = (nokogiriTuplePtr)doc->_private;
|
50
43
|
st_insert(tuple->unlinkedNodes, (st_data_t)node, (st_data_t)node);
|
51
44
|
}
|
@@ -54,7 +47,7 @@ void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
|
|
54
47
|
{
|
55
48
|
nokogiriTuplePtr tuple;
|
56
49
|
|
57
|
-
if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
|
50
|
+
if (doc->type == XML_DOCUMENT_FRAG_NODE) { doc = doc->doc; }
|
58
51
|
tuple = (nokogiriTuplePtr)doc->_private;
|
59
52
|
st_insert(tuple->unlinkedNodes, (st_data_t)ns, (st_data_t)ns);
|
60
53
|
}
|
@@ -62,10 +55,10 @@ void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
|
|
62
55
|
void Init_nokogiri()
|
63
56
|
{
|
64
57
|
xmlMemSetup(
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
58
|
+
(xmlFreeFunc)ruby_xfree,
|
59
|
+
(xmlMallocFunc)ruby_xmalloc,
|
60
|
+
(xmlReallocFunc)ruby_xrealloc,
|
61
|
+
ruby_strdup
|
69
62
|
);
|
70
63
|
|
71
64
|
mNokogiri = rb_define_module("Nokogiri");
|
@@ -75,33 +68,26 @@ void Init_nokogiri()
|
|
75
68
|
mNokogiriXmlSax = rb_define_module_under(mNokogiriXml, "SAX");
|
76
69
|
mNokogiriHtmlSax = rb_define_module_under(mNokogiriHtml, "SAX");
|
77
70
|
|
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), " "));
|
71
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION));
|
72
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xmlParserVersion));
|
73
|
+
|
74
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION));
|
75
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xsltEngineVersion));
|
76
|
+
|
77
|
+
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
|
78
|
+
rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
|
79
|
+
#ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
|
80
|
+
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qtrue);
|
81
|
+
#else
|
82
|
+
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
|
83
|
+
#endif
|
84
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
|
85
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
|
101
86
|
#else
|
102
|
-
rb_const_set(mNokogiri, rb_intern("
|
103
|
-
rb_const_set(mNokogiri, rb_intern("
|
104
|
-
rb_const_set(mNokogiri, rb_intern("
|
87
|
+
rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qfalse);
|
88
|
+
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
|
89
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), Qnil);
|
90
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), Qnil);
|
105
91
|
#endif
|
106
92
|
|
107
93
|
#ifdef LIBXML_ICONV_ENABLED
|
@@ -110,6 +96,10 @@ void Init_nokogiri()
|
|
110
96
|
rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse);
|
111
97
|
#endif
|
112
98
|
|
99
|
+
#ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS
|
100
|
+
rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
|
101
|
+
#endif
|
102
|
+
|
113
103
|
xmlInitParser();
|
114
104
|
|
115
105
|
init_xml_document();
|
@@ -144,4 +134,5 @@ void Init_nokogiri()
|
|
144
134
|
init_xml_relax_ng();
|
145
135
|
init_nokogiri_io();
|
146
136
|
init_xml_encoding_handler();
|
137
|
+
init_test_global_handlers();
|
147
138
|
}
|
data/ext/nokogiri/nokogiri.h
CHANGED
@@ -1,20 +1,25 @@
|
|
1
1
|
#ifndef NOKOGIRI_NATIVE
|
2
2
|
#define NOKOGIRI_NATIVE
|
3
3
|
|
4
|
+
#if _MSC_VER
|
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>
|
16
|
+
#endif
|
17
|
+
|
4
18
|
#include <stdlib.h>
|
5
19
|
#include <string.h>
|
6
20
|
#include <assert.h>
|
7
21
|
#include <stdarg.h>
|
8
|
-
|
9
|
-
#ifdef USE_INCLUDED_VASPRINTF
|
10
|
-
int vasprintf (char **strp, const char *fmt, va_list ap);
|
11
|
-
#else
|
12
|
-
|
13
|
-
#define _GNU_SOURCE
|
14
|
-
# include <stdio.h>
|
15
|
-
#undef _GNU_SOURCE
|
16
|
-
|
17
|
-
#endif
|
22
|
+
#include <stdio.h>
|
18
23
|
|
19
24
|
#include <libxml/parser.h>
|
20
25
|
#include <libxml/entities.h>
|
@@ -31,6 +36,7 @@ int vasprintf (char **strp, const char *fmt, va_list ap);
|
|
31
36
|
#include <libxslt/extensions.h>
|
32
37
|
#include <libxslt/xsltconfig.h>
|
33
38
|
#include <libxml/c14n.h>
|
39
|
+
|
34
40
|
#include <ruby.h>
|
35
41
|
#include <ruby/st.h>
|
36
42
|
#include <ruby/encoding.h>
|
@@ -94,25 +100,27 @@ extern VALUE mNokogiriHtml ;
|
|
94
100
|
extern VALUE mNokogiriHtmlSax ;
|
95
101
|
extern VALUE mNokogiriXslt ;
|
96
102
|
|
103
|
+
int vasprintf(char **strp, const char *fmt, va_list ap);
|
104
|
+
|
97
105
|
void nokogiri_root_node(xmlNodePtr);
|
98
106
|
void nokogiri_root_nsdef(xmlNsPtr, xmlDocPtr);
|
99
107
|
|
100
108
|
#ifdef DEBUG
|
101
109
|
|
102
|
-
#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);
|
103
|
-
#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);
|
104
112
|
|
105
113
|
#else
|
106
114
|
|
107
|
-
#define NOKOGIRI_DEBUG_START(p)
|
108
|
-
#define NOKOGIRI_DEBUG_END(p)
|
115
|
+
# define NOKOGIRI_DEBUG_START(p)
|
116
|
+
# define NOKOGIRI_DEBUG_END(p)
|
109
117
|
|
110
118
|
#endif
|
111
119
|
|
112
120
|
#ifndef __builtin_expect
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
121
|
+
# if defined(__GNUC__)
|
122
|
+
# define __builtin_expect(expr, c) __builtin_expect((long)(expr), (long)(c))
|
123
|
+
# endif
|
116
124
|
#endif
|
117
125
|
|
118
126
|
#define XMLNS_PREFIX "xmlns"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
#include "libxml/xmlerror.h"
|
3
|
+
|
4
|
+
static VALUE foreign_error_handler_block = Qnil;
|
5
|
+
|
6
|
+
static void foreign_error_handler(void* user_data, xmlErrorPtr c_error)
|
7
|
+
{
|
8
|
+
rb_funcall(foreign_error_handler_block, rb_intern("call"), 0);
|
9
|
+
}
|
10
|
+
|
11
|
+
/*
|
12
|
+
* call-seq:
|
13
|
+
* __foreign_error_handler { ... } -> nil
|
14
|
+
*
|
15
|
+
* Override libxml2's global error handlers to call the block. This method thus has very little
|
16
|
+
* value except to test that Nokogiri is properly setting error handlers elsewhere in the code. See
|
17
|
+
* test/helper.rb for how this is being used.
|
18
|
+
*/
|
19
|
+
static VALUE
|
20
|
+
rb_foreign_error_handler(VALUE klass)
|
21
|
+
{
|
22
|
+
rb_need_block();
|
23
|
+
foreign_error_handler_block = rb_block_proc();
|
24
|
+
xmlSetStructuredErrorFunc(NULL, foreign_error_handler);
|
25
|
+
return Qnil;
|
26
|
+
}
|
27
|
+
|
28
|
+
/*
|
29
|
+
* Document-module: Nokogiri::Test
|
30
|
+
*
|
31
|
+
* The Nokogiri::Test module should only be used for testing Nokogiri.
|
32
|
+
* Do NOT use this outside of the Nokogiri test suite.
|
33
|
+
*/
|
34
|
+
void
|
35
|
+
init_test_global_handlers()
|
36
|
+
{
|
37
|
+
VALUE mNokogiri = rb_define_module("Nokogiri");
|
38
|
+
VALUE mNokogiriTest = rb_define_module_under(mNokogiri, "Test");
|
39
|
+
|
40
|
+
rb_define_singleton_method(mNokogiriTest, "__foreign_error_handler", rb_foreign_error_handler, 0);
|
41
|
+
}
|
data/ext/nokogiri/xml_document.c
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#include <xml_document.h>
|
2
2
|
|
3
|
-
static int
|
3
|
+
static int dealloc_node_i2(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
|
4
4
|
{
|
5
5
|
switch(node->type) {
|
6
6
|
case XML_ATTRIBUTE_NODE:
|
@@ -20,6 +20,11 @@ static int dealloc_node_i(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
|
|
20
20
|
return ST_CONTINUE;
|
21
21
|
}
|
22
22
|
|
23
|
+
static int dealloc_node_i(st_data_t key, st_data_t node, st_data_t doc)
|
24
|
+
{
|
25
|
+
return dealloc_node_i2((xmlNodePtr)key, (xmlNodePtr)node, (xmlDocPtr)doc);
|
26
|
+
}
|
27
|
+
|
23
28
|
static void remove_private(xmlNodePtr node)
|
24
29
|
{
|
25
30
|
xmlNodePtr child;
|
@@ -501,7 +506,7 @@ static int block_caller(void * ctx, xmlNodePtr _node, xmlNodePtr _parent)
|
|
501
506
|
* The block must return a non-nil, non-false value if the +obj+ passed in
|
502
507
|
* should be included in the canonicalized document.
|
503
508
|
*/
|
504
|
-
static VALUE
|
509
|
+
static VALUE nokogiri_xml_document_canonicalize(int argc, VALUE* argv, VALUE self)
|
505
510
|
{
|
506
511
|
VALUE mode;
|
507
512
|
VALUE incl_ns;
|
@@ -582,7 +587,7 @@ void init_xml_document()
|
|
582
587
|
rb_define_method(klass, "encoding", encoding, 0);
|
583
588
|
rb_define_method(klass, "encoding=", set_encoding, 1);
|
584
589
|
rb_define_method(klass, "version", version, 0);
|
585
|
-
rb_define_method(klass, "canonicalize",
|
590
|
+
rb_define_method(klass, "canonicalize", nokogiri_xml_document_canonicalize, -1);
|
586
591
|
rb_define_method(klass, "dup", duplicate_document, -1);
|
587
592
|
rb_define_method(klass, "url", url, 0);
|
588
593
|
rb_define_method(klass, "create_entity", create_entity, -1);
|
data/ext/nokogiri/xml_io.c
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
static ID id_read, id_write;
|
4
4
|
|
5
|
-
VALUE read_check(VALUE
|
5
|
+
VALUE read_check(VALUE val) {
|
6
|
+
VALUE *args = (VALUE *)val;
|
6
7
|
return rb_funcall(args[0], id_read, 1, args[1]);
|
7
8
|
}
|
8
9
|
|
9
|
-
VALUE read_failed(
|
10
|
-
|
10
|
+
VALUE read_failed(VALUE arg, VALUE exc) {
|
11
|
+
return Qundef;
|
11
12
|
}
|
12
13
|
|
13
14
|
int io_read_callback(void * ctx, char * buffer, int len) {
|
@@ -30,12 +31,13 @@ int io_read_callback(void * ctx, char * buffer, int len) {
|
|
30
31
|
return (int)safe_len;
|
31
32
|
}
|
32
33
|
|
33
|
-
VALUE write_check(VALUE
|
34
|
+
VALUE write_check(VALUE val) {
|
35
|
+
VALUE *args = (VALUE *)val;
|
34
36
|
return rb_funcall(args[0], id_write, 1, args[1]);
|
35
37
|
}
|
36
38
|
|
37
|
-
VALUE write_failed(
|
38
|
-
|
39
|
+
VALUE write_failed(VALUE arg, VALUE exc) {
|
40
|
+
return Qundef;
|
39
41
|
}
|
40
42
|
|
41
43
|
int io_write_callback(void * ctx, char * buffer, int len) {
|
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_reader.c
CHANGED
@@ -28,35 +28,24 @@ static int has_attributes(xmlTextReaderPtr reader)
|
|
28
28
|
static void Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
|
29
29
|
{
|
30
30
|
xmlNsPtr ns;
|
31
|
-
|
32
|
-
char *key ;
|
33
|
-
size_t keylen ;
|
31
|
+
VALUE key;
|
34
32
|
|
35
33
|
if (node->type != XML_ELEMENT_NODE) return ;
|
36
34
|
|
37
35
|
ns = node->nsDef;
|
38
36
|
while (ns != NULL) {
|
39
37
|
|
40
|
-
|
41
|
-
if (keylen > XMLNS_BUFFER_LEN) {
|
42
|
-
key = (char*)malloc(keylen) ;
|
43
|
-
} else {
|
44
|
-
key = buffer ;
|
45
|
-
}
|
46
|
-
|
38
|
+
key = rb_enc_str_new_cstr(XMLNS_PREFIX, rb_utf8_encoding());
|
47
39
|
if (ns->prefix) {
|
48
|
-
|
49
|
-
|
50
|
-
sprintf(key, "%s", XMLNS_PREFIX);
|
40
|
+
rb_str_cat_cstr(key, ":");
|
41
|
+
rb_str_cat_cstr(key, (const char*)ns->prefix);
|
51
42
|
}
|
52
43
|
|
44
|
+
key = rb_str_conv_enc(key, rb_utf8_encoding(), rb_default_internal_encoding());
|
53
45
|
rb_hash_aset(attr_hash,
|
54
|
-
|
46
|
+
key,
|
55
47
|
(ns->href ? NOKOGIRI_STR_NEW2(ns->href) : Qnil)
|
56
48
|
);
|
57
|
-
if (key != buffer) {
|
58
|
-
free(key);
|
59
|
-
}
|
60
49
|
ns = ns->next ;
|
61
50
|
}
|
62
51
|
}
|
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
|
}
|