nokogiri 1.13.6 → 1.14.2
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 +39 -0
- data/LICENSE-DEPENDENCIES.md +830 -509
- data/LICENSE.md +1 -1
- data/README.md +18 -11
- data/dependencies.yml +33 -15
- data/ext/nokogiri/extconf.rb +100 -24
- data/ext/nokogiri/gumbo.c +21 -11
- data/ext/nokogiri/html4_document.c +2 -2
- data/ext/nokogiri/html4_element_description.c +1 -1
- data/ext/nokogiri/html4_entity_lookup.c +2 -2
- data/ext/nokogiri/html4_sax_parser_context.c +1 -6
- data/ext/nokogiri/html4_sax_push_parser.c +1 -1
- data/ext/nokogiri/nokogiri.c +38 -51
- data/ext/nokogiri/nokogiri.h +26 -14
- data/ext/nokogiri/test_global_handlers.c +1 -1
- data/ext/nokogiri/xml_attr.c +3 -3
- data/ext/nokogiri/xml_attribute_decl.c +5 -5
- data/ext/nokogiri/xml_cdata.c +3 -3
- data/ext/nokogiri/xml_comment.c +1 -1
- data/ext/nokogiri/xml_document.c +23 -14
- data/ext/nokogiri/xml_document_fragment.c +1 -1
- data/ext/nokogiri/xml_dtd.c +9 -9
- data/ext/nokogiri/xml_element_content.c +3 -3
- data/ext/nokogiri/xml_element_decl.c +5 -5
- data/ext/nokogiri/xml_encoding_handler.c +3 -3
- data/ext/nokogiri/xml_entity_decl.c +6 -6
- data/ext/nokogiri/xml_entity_reference.c +1 -1
- data/ext/nokogiri/xml_namespace.c +80 -14
- data/ext/nokogiri/xml_node.c +363 -82
- data/ext/nokogiri/xml_node_set.c +4 -6
- data/ext/nokogiri/xml_processing_instruction.c +1 -1
- data/ext/nokogiri/xml_reader.c +97 -22
- data/ext/nokogiri/xml_relax_ng.c +1 -3
- data/ext/nokogiri/xml_sax_parser.c +23 -17
- data/ext/nokogiri/xml_sax_parser_context.c +1 -6
- data/ext/nokogiri/xml_sax_push_parser.c +1 -3
- data/ext/nokogiri/xml_schema.c +4 -6
- data/ext/nokogiri/xml_syntax_error.c +1 -1
- data/ext/nokogiri/xml_text.c +2 -2
- data/ext/nokogiri/xml_xpath_context.c +91 -84
- data/ext/nokogiri/xslt_stylesheet.c +15 -14
- data/gumbo-parser/Makefile +10 -0
- data/gumbo-parser/src/attribute.h +1 -1
- data/gumbo-parser/src/error.c +2 -2
- data/gumbo-parser/src/error.h +1 -1
- data/gumbo-parser/src/foreign_attrs.c +2 -2
- data/gumbo-parser/src/{gumbo.h → nokogiri_gumbo.h} +1 -0
- data/gumbo-parser/src/parser.c +8 -5
- data/gumbo-parser/src/replacement.h +1 -1
- data/gumbo-parser/src/string_buffer.h +1 -1
- data/gumbo-parser/src/string_piece.c +1 -1
- data/gumbo-parser/src/svg_attrs.c +2 -2
- data/gumbo-parser/src/svg_tags.c +2 -2
- data/gumbo-parser/src/tag.c +2 -1
- data/gumbo-parser/src/tag_lookup.c +7 -7
- data/gumbo-parser/src/tag_lookup.gperf +1 -0
- data/gumbo-parser/src/tag_lookup.h +1 -1
- data/gumbo-parser/src/token_buffer.h +1 -1
- data/gumbo-parser/src/tokenizer.c +1 -1
- data/gumbo-parser/src/tokenizer.h +1 -1
- data/gumbo-parser/src/utf8.c +1 -1
- data/gumbo-parser/src/utf8.h +1 -1
- data/gumbo-parser/src/util.c +1 -3
- data/gumbo-parser/src/util.h +4 -0
- data/gumbo-parser/src/vector.h +1 -1
- data/lib/nokogiri/css/node.rb +2 -2
- data/lib/nokogiri/css/xpath_visitor.rb +5 -3
- data/lib/nokogiri/css.rb +6 -0
- data/lib/nokogiri/decorators/slop.rb +1 -1
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +3 -2
- data/lib/nokogiri/html4/document.rb +2 -121
- data/lib/nokogiri/html4/element_description_defaults.rb +6 -12
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/html4.rb +1 -0
- data/lib/nokogiri/html5/document.rb +113 -36
- data/lib/nokogiri/html5/document_fragment.rb +9 -2
- data/lib/nokogiri/html5/node.rb +3 -5
- data/lib/nokogiri/html5.rb +127 -216
- data/lib/nokogiri/jruby/dependencies.rb +1 -19
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +11 -10
- data/lib/nokogiri/xml/attr.rb +49 -0
- data/lib/nokogiri/xml/builder.rb +1 -1
- data/lib/nokogiri/xml/document.rb +103 -55
- data/lib/nokogiri/xml/document_fragment.rb +49 -6
- data/lib/nokogiri/xml/namespace.rb +42 -0
- data/lib/nokogiri/xml/node/save_options.rb +6 -4
- data/lib/nokogiri/xml/node.rb +190 -35
- data/lib/nokogiri/xml/node_set.rb +88 -9
- data/lib/nokogiri/xml/parse_options.rb +129 -50
- data/lib/nokogiri/xml/pp/node.rb +6 -4
- data/lib/nokogiri/xml/processing_instruction.rb +2 -1
- data/lib/nokogiri/xml/reader.rb +6 -8
- data/lib/nokogiri/xml/sax/parser.rb +2 -3
- data/lib/nokogiri/xslt.rb +1 -1
- data/lib/nokogiri.rb +3 -11
- data/lib/xsd/xmlparser/nokogiri.rb +3 -1
- data/ports/archives/libxml2-2.10.3.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.37.tar.xz +0 -0
- metadata +11 -242
- data/patches/libxml2/0004-use-glibc-strlen.patch +0 -53
- data/patches/libxml2/0005-avoid-isnan-isinf.patch +0 -81
- data/patches/libxml2/0006-update-automake-files-for-arm64.patch +0 -3040
- data/patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch +0 -61
- data/ports/archives/libxml2-2.9.14.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.35.tar.xz +0 -0
data/ext/nokogiri/nokogiri.c
CHANGED
@@ -49,34 +49,11 @@ void noko_init_html_sax_push_parser(void);
|
|
49
49
|
void noko_init_gumbo(void);
|
50
50
|
void noko_init_test_global_handlers(void);
|
51
51
|
|
52
|
-
static ID id_read, id_write;
|
53
|
-
|
54
|
-
|
55
|
-
#ifndef HAVE_VASPRINTF
|
56
|
-
/*
|
57
|
-
* Thank you Geoffroy Couprie for this implementation of vasprintf!
|
58
|
-
*/
|
59
|
-
int
|
60
|
-
vasprintf(char **strp, const char *fmt, va_list ap)
|
61
|
-
{
|
62
|
-
/* Mingw32/64 have a broken vsnprintf implementation that fails when
|
63
|
-
* using a zero-byte limit in order to retrieve the required size for malloc.
|
64
|
-
* So we use a one byte buffer instead.
|
65
|
-
*/
|
66
|
-
char tmp[1];
|
67
|
-
int len = vsnprintf(tmp, 1, fmt, ap) + 1;
|
68
|
-
char *res = (char *)malloc((unsigned int)len);
|
69
|
-
if (res == NULL) {
|
70
|
-
return -1;
|
71
|
-
}
|
72
|
-
*strp = res;
|
73
|
-
return vsnprintf(res, (unsigned int)len, fmt, ap);
|
74
|
-
}
|
75
|
-
#endif
|
52
|
+
static ID id_read, id_write, id_external_encoding;
|
76
53
|
|
77
54
|
|
78
55
|
static VALUE
|
79
|
-
|
56
|
+
noko_io_read_check(VALUE val)
|
80
57
|
{
|
81
58
|
VALUE *args = (VALUE *)val;
|
82
59
|
return rb_funcall(args[0], id_read, 1, args[1]);
|
@@ -84,75 +61,84 @@ read_check(VALUE val)
|
|
84
61
|
|
85
62
|
|
86
63
|
static VALUE
|
87
|
-
|
64
|
+
noko_io_read_failed(VALUE arg, VALUE exc)
|
88
65
|
{
|
89
66
|
return Qundef;
|
90
67
|
}
|
91
68
|
|
92
69
|
|
93
70
|
int
|
94
|
-
noko_io_read(void *
|
71
|
+
noko_io_read(void *io, char *c_buffer, int c_buffer_len)
|
95
72
|
{
|
96
|
-
VALUE
|
97
|
-
|
73
|
+
VALUE rb_io = (VALUE)io;
|
74
|
+
VALUE rb_read_string, rb_args[2];
|
75
|
+
size_t n_bytes_read, safe_len;
|
98
76
|
|
99
|
-
|
100
|
-
|
77
|
+
rb_args[0] = rb_io;
|
78
|
+
rb_args[1] = INT2NUM(c_buffer_len);
|
101
79
|
|
102
|
-
|
80
|
+
rb_read_string = rb_rescue(noko_io_read_check, (VALUE)rb_args, noko_io_read_failed, 0);
|
103
81
|
|
104
|
-
if (NIL_P(
|
105
|
-
if (
|
106
|
-
if (TYPE(
|
82
|
+
if (NIL_P(rb_read_string)) { return 0; }
|
83
|
+
if (rb_read_string == Qundef) { return -1; }
|
84
|
+
if (TYPE(rb_read_string) != T_STRING) { return -1; }
|
107
85
|
|
108
|
-
|
109
|
-
safe_len =
|
110
|
-
memcpy(
|
86
|
+
n_bytes_read = (size_t)RSTRING_LEN(rb_read_string);
|
87
|
+
safe_len = (n_bytes_read > (size_t)c_buffer_len) ? (size_t)c_buffer_len : n_bytes_read;
|
88
|
+
memcpy(c_buffer, StringValuePtr(rb_read_string), safe_len);
|
111
89
|
|
112
90
|
return (int)safe_len;
|
113
91
|
}
|
114
92
|
|
115
93
|
|
116
94
|
static VALUE
|
117
|
-
|
95
|
+
noko_io_write_check(VALUE rb_args)
|
118
96
|
{
|
119
|
-
VALUE
|
120
|
-
|
97
|
+
VALUE rb_io = ((VALUE *)rb_args)[0];
|
98
|
+
VALUE rb_output = ((VALUE *)rb_args)[1];
|
99
|
+
return rb_funcall(rb_io, id_write, 1, rb_output);
|
121
100
|
}
|
122
101
|
|
123
102
|
|
124
103
|
static VALUE
|
125
|
-
|
104
|
+
noko_io_write_failed(VALUE arg, VALUE exc)
|
126
105
|
{
|
127
106
|
return Qundef;
|
128
107
|
}
|
129
108
|
|
130
109
|
|
131
110
|
int
|
132
|
-
noko_io_write(void *
|
111
|
+
noko_io_write(void *io, char *c_buffer, int c_buffer_len)
|
133
112
|
{
|
134
|
-
VALUE
|
113
|
+
VALUE rb_args[2], rb_n_bytes_written;
|
114
|
+
VALUE rb_io = (VALUE)io;
|
115
|
+
VALUE rb_enc = Qnil;
|
116
|
+
rb_encoding *io_encoding;
|
135
117
|
|
136
|
-
|
137
|
-
|
118
|
+
if (rb_respond_to(rb_io, id_external_encoding)) {
|
119
|
+
rb_enc = rb_funcall(rb_io, id_external_encoding, 0);
|
120
|
+
}
|
121
|
+
io_encoding = RB_NIL_P(rb_enc) ? rb_ascii8bit_encoding() : rb_to_encoding(rb_enc);
|
138
122
|
|
139
|
-
|
123
|
+
rb_args[0] = rb_io;
|
124
|
+
rb_args[1] = rb_enc_str_new(c_buffer, (long)c_buffer_len, io_encoding);
|
140
125
|
|
141
|
-
|
126
|
+
rb_n_bytes_written = rb_rescue(noko_io_write_check, (VALUE)rb_args, noko_io_write_failed, 0);
|
127
|
+
if (rb_n_bytes_written == Qundef) { return -1; }
|
142
128
|
|
143
|
-
return NUM2INT(
|
129
|
+
return NUM2INT(rb_n_bytes_written);
|
144
130
|
}
|
145
131
|
|
146
132
|
|
147
133
|
int
|
148
|
-
noko_io_close(void *
|
134
|
+
noko_io_close(void *io)
|
149
135
|
{
|
150
136
|
return 0;
|
151
137
|
}
|
152
138
|
|
153
139
|
|
154
140
|
void
|
155
|
-
Init_nokogiri()
|
141
|
+
Init_nokogiri(void)
|
156
142
|
{
|
157
143
|
mNokogiri = rb_define_module("Nokogiri");
|
158
144
|
mNokogiriGumbo = rb_define_module_under(mNokogiri, "Gumbo");
|
@@ -275,4 +261,5 @@ Init_nokogiri()
|
|
275
261
|
|
276
262
|
id_read = rb_intern("read");
|
277
263
|
id_write = rb_intern("write");
|
264
|
+
id_external_encoding = rb_intern("external_encoding");
|
278
265
|
}
|
data/ext/nokogiri/nokogiri.h
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#ifndef NOKOGIRI_NATIVE
|
2
2
|
#define NOKOGIRI_NATIVE
|
3
3
|
|
4
|
+
#include <ruby/defines.h> // https://github.com/sparklemotion/nokogiri/issues/2696
|
5
|
+
|
4
6
|
#ifdef _MSC_VER
|
5
7
|
# ifndef WIN32_LEAN_AND_MEAN
|
6
8
|
# define WIN32_LEAN_AND_MEAN
|
@@ -23,7 +25,6 @@
|
|
23
25
|
# define NOKOPUBVAR extern
|
24
26
|
#endif
|
25
27
|
|
26
|
-
|
27
28
|
#include <stdlib.h>
|
28
29
|
#include <string.h>
|
29
30
|
#include <assert.h>
|
@@ -75,22 +76,25 @@ xmlNodePtr xmlLastElementChild(xmlNodePtr parent);
|
|
75
76
|
#define NOKOGIRI_STR_NEW(str, len) rb_external_str_new_with_enc((const char *)(str), (long)(len), rb_utf8_encoding())
|
76
77
|
#define RBSTR_OR_QNIL(_str) (_str ? NOKOGIRI_STR_NEW2(_str) : Qnil)
|
77
78
|
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#else
|
82
|
-
#
|
83
|
-
#
|
79
|
+
#ifndef NORETURN_DECL
|
80
|
+
# if defined(__GNUC__)
|
81
|
+
# define NORETURN_DECL __attribute__ ((noreturn))
|
82
|
+
# else
|
83
|
+
# define NORETURN_DECL
|
84
|
+
# endif
|
84
85
|
#endif
|
85
86
|
|
86
|
-
#ifndef
|
87
|
+
#ifndef PRINTFLIKE_DECL
|
87
88
|
# if defined(__GNUC__)
|
88
|
-
# define
|
89
|
+
# define PRINTFLIKE_DECL(stringidx, argidx) __attribute__ ((format(printf,stringidx,argidx)))
|
89
90
|
# else
|
90
|
-
# define
|
91
|
+
# define PRINTFLIKE_DECL(stringidx, argidx)
|
91
92
|
# endif
|
92
93
|
#endif
|
93
94
|
|
95
|
+
#if defined(TRUFFLERUBY) && !defined(NOKOGIRI_PACKAGED_LIBRARIES)
|
96
|
+
# define TRUFFLERUBY_NOKOGIRI_SYSTEM_LIBRARIES
|
97
|
+
#endif
|
94
98
|
|
95
99
|
NOKOPUBVAR VALUE mNokogiri ;
|
96
100
|
NOKOPUBVAR VALUE mNokogiriGumbo ;
|
@@ -162,7 +166,6 @@ typedef struct _nokogiriXsltStylesheetTuple {
|
|
162
166
|
VALUE func_instances;
|
163
167
|
} nokogiriXsltStylesheetTuple;
|
164
168
|
|
165
|
-
int vasprintf(char **strp, const char *fmt, va_list ap);
|
166
169
|
void noko_xml_document_pin_node(xmlNodePtr);
|
167
170
|
void noko_xml_document_pin_namespace(xmlNsPtr, xmlDocPtr);
|
168
171
|
|
@@ -170,6 +173,9 @@ int noko_io_read(void *ctx, char *buffer, int len);
|
|
170
173
|
int noko_io_write(void *ctx, char *buffer, int len);
|
171
174
|
int noko_io_close(void *ctx);
|
172
175
|
|
176
|
+
#define Noko_Node_Get_Struct(obj,type,sval) ((sval) = (type*)DATA_PTR(obj))
|
177
|
+
#define Noko_Namespace_Get_Struct(obj,type,sval) ((sval) = (type*)DATA_PTR(obj))
|
178
|
+
|
173
179
|
VALUE noko_xml_node_wrap(VALUE klass, xmlNodePtr node) ;
|
174
180
|
VALUE noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set) ;
|
175
181
|
VALUE noko_xml_node_attrs(xmlNodePtr node) ;
|
@@ -195,18 +201,24 @@ NOKOPUBFUN VALUE Nokogiri_wrap_xml_document(VALUE klass,
|
|
195
201
|
#define NOKOGIRI_SAX_SELF(_ctxt) ((nokogiriSAXTuplePtr)(_ctxt))->self
|
196
202
|
#define NOKOGIRI_SAX_CTXT(_ctxt) ((nokogiriSAXTuplePtr)(_ctxt))->ctxt
|
197
203
|
#define NOKOGIRI_SAX_TUPLE_NEW(_ctxt, _self) nokogiri_sax_tuple_new(_ctxt, _self)
|
198
|
-
#define NOKOGIRI_SAX_TUPLE_DESTROY(_tuple)
|
204
|
+
#define NOKOGIRI_SAX_TUPLE_DESTROY(_tuple) ruby_xfree(_tuple)
|
199
205
|
|
200
206
|
#define DISCARD_CONST_QUAL(t, v) ((t)(uintptr_t)(v))
|
201
207
|
#define DISCARD_CONST_QUAL_XMLCHAR(v) DISCARD_CONST_QUAL(xmlChar *, v)
|
202
208
|
|
209
|
+
#if HAVE_RB_CATEGORY_WARNING
|
210
|
+
# define NOKO_WARN_DEPRECATION(message) rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, message)
|
211
|
+
#else
|
212
|
+
# define NOKO_WARN_DEPRECATION(message) rb_warning(message)
|
213
|
+
#endif
|
214
|
+
|
203
215
|
void Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state);
|
204
216
|
void Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state, void *user_data,
|
205
217
|
xmlStructuredErrorFunc handler);
|
206
218
|
void Nokogiri_structured_error_func_restore(libxmlStructuredErrorHandlerState *handler_state);
|
207
219
|
VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error);
|
208
220
|
void Nokogiri_error_array_pusher(void *ctx, xmlErrorPtr error);
|
209
|
-
|
221
|
+
NORETURN_DECL void Nokogiri_error_raise(void *ctx, xmlErrorPtr error);
|
210
222
|
void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler,
|
211
223
|
const char *function_name) ;
|
212
224
|
|
@@ -214,7 +226,7 @@ static inline
|
|
214
226
|
nokogiriSAXTuplePtr
|
215
227
|
nokogiri_sax_tuple_new(xmlParserCtxtPtr ctxt, VALUE self)
|
216
228
|
{
|
217
|
-
nokogiriSAXTuplePtr tuple =
|
229
|
+
nokogiriSAXTuplePtr tuple = ruby_xmalloc(sizeof(nokogiriSAXTuple));
|
218
230
|
tuple->self = self;
|
219
231
|
tuple->ctxt = ctxt;
|
220
232
|
return tuple;
|
@@ -32,7 +32,7 @@ rb_foreign_error_handler(VALUE klass)
|
|
32
32
|
* Do NOT use this outside of the Nokogiri test suite.
|
33
33
|
*/
|
34
34
|
void
|
35
|
-
noko_init_test_global_handlers()
|
35
|
+
noko_init_test_global_handlers(void)
|
36
36
|
{
|
37
37
|
VALUE mNokogiriTest = rb_define_module_under(mNokogiri, "Test");
|
38
38
|
|
data/ext/nokogiri/xml_attr.c
CHANGED
@@ -16,7 +16,7 @@ set_value(VALUE self, VALUE content)
|
|
16
16
|
xmlChar *value;
|
17
17
|
xmlNode *cur;
|
18
18
|
|
19
|
-
|
19
|
+
Noko_Node_Get_Struct(self, xmlAttr, attr);
|
20
20
|
|
21
21
|
if (attr->children) {
|
22
22
|
xmlFreeNodeList(attr->children);
|
@@ -68,7 +68,7 @@ new (int argc, VALUE *argv, VALUE klass)
|
|
68
68
|
rb_raise(rb_eArgError, "parameter must be a Nokogiri::XML::Document");
|
69
69
|
}
|
70
70
|
|
71
|
-
|
71
|
+
Noko_Node_Get_Struct(document, xmlDoc, xml_doc);
|
72
72
|
|
73
73
|
node = xmlNewDocProp(
|
74
74
|
xml_doc,
|
@@ -89,7 +89,7 @@ new (int argc, VALUE *argv, VALUE klass)
|
|
89
89
|
}
|
90
90
|
|
91
91
|
void
|
92
|
-
noko_init_xml_attr()
|
92
|
+
noko_init_xml_attr(void)
|
93
93
|
{
|
94
94
|
assert(cNokogiriXmlNode);
|
95
95
|
/*
|
@@ -12,8 +12,8 @@ static VALUE
|
|
12
12
|
attribute_type(VALUE self)
|
13
13
|
{
|
14
14
|
xmlAttributePtr node;
|
15
|
-
|
16
|
-
return INT2NUM(
|
15
|
+
Noko_Node_Get_Struct(self, xmlAttribute, node);
|
16
|
+
return INT2NUM(node->atype);
|
17
17
|
}
|
18
18
|
|
19
19
|
/*
|
@@ -26,7 +26,7 @@ static VALUE
|
|
26
26
|
default_value(VALUE self)
|
27
27
|
{
|
28
28
|
xmlAttributePtr node;
|
29
|
-
|
29
|
+
Noko_Node_Get_Struct(self, xmlAttribute, node);
|
30
30
|
|
31
31
|
if (node->defaultValue) { return NOKOGIRI_STR_NEW2(node->defaultValue); }
|
32
32
|
return Qnil;
|
@@ -45,7 +45,7 @@ enumeration(VALUE self)
|
|
45
45
|
xmlEnumerationPtr enm;
|
46
46
|
VALUE list;
|
47
47
|
|
48
|
-
|
48
|
+
Noko_Node_Get_Struct(self, xmlAttribute, node);
|
49
49
|
|
50
50
|
list = rb_ary_new();
|
51
51
|
enm = node->tree;
|
@@ -59,7 +59,7 @@ enumeration(VALUE self)
|
|
59
59
|
}
|
60
60
|
|
61
61
|
void
|
62
|
-
noko_init_xml_attribute_decl()
|
62
|
+
noko_init_xml_attribute_decl(void)
|
63
63
|
{
|
64
64
|
assert(cNokogiriXmlNode);
|
65
65
|
cNokogiriXmlAttributeDecl = rb_define_class_under(mNokogiriXml, "AttributeDecl", cNokogiriXmlNode);
|
data/ext/nokogiri/xml_cdata.c
CHANGED
@@ -25,11 +25,11 @@ new (int argc, VALUE *argv, VALUE klass)
|
|
25
25
|
|
26
26
|
rb_scan_args(argc, argv, "2*", &doc, &content, &rest);
|
27
27
|
|
28
|
-
|
28
|
+
Noko_Node_Get_Struct(doc, xmlDoc, xml_doc);
|
29
29
|
|
30
30
|
if (!NIL_P(content)) {
|
31
31
|
content_str = (xmlChar *)StringValuePtr(content);
|
32
|
-
content_str_len =
|
32
|
+
content_str_len = RSTRING_LENINT(content);
|
33
33
|
}
|
34
34
|
|
35
35
|
node = xmlNewCDataBlock(xml_doc->doc, content_str, content_str_len);
|
@@ -45,7 +45,7 @@ new (int argc, VALUE *argv, VALUE klass)
|
|
45
45
|
}
|
46
46
|
|
47
47
|
void
|
48
|
-
noko_init_xml_cdata()
|
48
|
+
noko_init_xml_cdata(void)
|
49
49
|
{
|
50
50
|
assert(cNokogiriXmlText);
|
51
51
|
/*
|
data/ext/nokogiri/xml_comment.c
CHANGED
data/ext/nokogiri/xml_document.c
CHANGED
@@ -65,14 +65,12 @@ dealloc(xmlDocPtr doc)
|
|
65
65
|
{
|
66
66
|
st_table *node_hash;
|
67
67
|
|
68
|
-
NOKOGIRI_DEBUG_START(doc);
|
69
|
-
|
70
68
|
node_hash = DOC_UNLINKED_NODE_HASH(doc);
|
71
69
|
|
72
70
|
st_foreach(node_hash, dealloc_node_i, (st_data_t)doc);
|
73
71
|
st_free_table(node_hash);
|
74
72
|
|
75
|
-
|
73
|
+
ruby_xfree(doc->_private);
|
76
74
|
|
77
75
|
/* When both Nokogiri and libxml-ruby are loaded, make sure that all nodes
|
78
76
|
* have their _private pointers cleared. This is to avoid libxml-ruby's
|
@@ -84,8 +82,6 @@ dealloc(xmlDocPtr doc)
|
|
84
82
|
}
|
85
83
|
|
86
84
|
xmlFreeDoc(doc);
|
87
|
-
|
88
|
-
NOKOGIRI_DEBUG_END(doc);
|
89
85
|
}
|
90
86
|
|
91
87
|
static void
|
@@ -104,7 +100,11 @@ recursively_remove_namespaces_from_node(xmlNodePtr node)
|
|
104
100
|
(node->type == XML_XINCLUDE_START) ||
|
105
101
|
(node->type == XML_XINCLUDE_END)) &&
|
106
102
|
node->nsDef) {
|
107
|
-
|
103
|
+
xmlNsPtr curr = node->nsDef;
|
104
|
+
while (curr) {
|
105
|
+
noko_xml_document_pin_namespace(curr, node->doc);
|
106
|
+
curr = curr->next;
|
107
|
+
}
|
108
108
|
node->nsDef = NULL;
|
109
109
|
}
|
110
110
|
|
@@ -161,7 +161,7 @@ rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
|
|
161
161
|
rb_obj_class(rb_new_root));
|
162
162
|
}
|
163
163
|
|
164
|
-
|
164
|
+
Noko_Node_Get_Struct(rb_new_root, xmlNode, c_new_root);
|
165
165
|
|
166
166
|
/* If the new root's document is not the same as the current document,
|
167
167
|
* then we need to dup the node in to this document. */
|
@@ -536,6 +536,7 @@ rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
|
|
536
536
|
VALUE rb_mode;
|
537
537
|
VALUE rb_namespaces;
|
538
538
|
VALUE rb_comments_p;
|
539
|
+
int c_mode = 0;
|
539
540
|
xmlChar **c_namespaces;
|
540
541
|
|
541
542
|
xmlDocPtr c_doc;
|
@@ -547,8 +548,16 @@ rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
|
|
547
548
|
VALUE rb_io;
|
548
549
|
|
549
550
|
rb_scan_args(argc, argv, "03", &rb_mode, &rb_namespaces, &rb_comments_p);
|
550
|
-
if (!NIL_P(rb_mode)) {
|
551
|
-
|
551
|
+
if (!NIL_P(rb_mode)) {
|
552
|
+
Check_Type(rb_mode, T_FIXNUM);
|
553
|
+
c_mode = NUM2INT(rb_mode);
|
554
|
+
}
|
555
|
+
if (!NIL_P(rb_namespaces)) {
|
556
|
+
Check_Type(rb_namespaces, T_ARRAY);
|
557
|
+
if (c_mode == XML_C14N_1_0 || c_mode == XML_C14N_1_1) {
|
558
|
+
rb_raise(rb_eRuntimeError, "This canonicalizer does not support this operation");
|
559
|
+
}
|
560
|
+
}
|
552
561
|
|
553
562
|
Data_Get_Struct(self, xmlDoc, c_doc);
|
554
563
|
|
@@ -569,7 +578,7 @@ rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
|
|
569
578
|
c_namespaces = NULL;
|
570
579
|
} else {
|
571
580
|
long ns_len = RARRAY_LEN(rb_namespaces);
|
572
|
-
c_namespaces =
|
581
|
+
c_namespaces = ruby_xcalloc((size_t)ns_len + 1, sizeof(xmlChar *));
|
573
582
|
for (int j = 0 ; j < ns_len ; j++) {
|
574
583
|
VALUE entry = rb_ary_entry(rb_namespaces, j);
|
575
584
|
c_namespaces[j] = (xmlChar *)StringValueCStr(entry);
|
@@ -577,12 +586,12 @@ rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
|
|
577
586
|
}
|
578
587
|
|
579
588
|
xmlC14NExecute(c_doc, c_callback_wrapper, rb_callback,
|
580
|
-
|
589
|
+
c_mode,
|
581
590
|
c_namespaces,
|
582
591
|
(int)RTEST(rb_comments_p),
|
583
592
|
c_obuf);
|
584
593
|
|
585
|
-
|
594
|
+
ruby_xfree(c_namespaces);
|
586
595
|
xmlOutputBufferClose(c_obuf);
|
587
596
|
|
588
597
|
return rb_funcall(rb_io, rb_intern("string"), 0);
|
@@ -600,7 +609,7 @@ noko_xml_document_wrap_with_init_args(VALUE klass, xmlDocPtr c_document, int arg
|
|
600
609
|
|
601
610
|
rb_document = Data_Wrap_Struct(klass, mark, dealloc, c_document);
|
602
611
|
|
603
|
-
tuple = (nokogiriTuplePtr)
|
612
|
+
tuple = (nokogiriTuplePtr)ruby_xmalloc(sizeof(nokogiriTuple));
|
604
613
|
tuple->doc = rb_document;
|
605
614
|
tuple->unlinkedNodes = st_init_numtable_with_size(128);
|
606
615
|
tuple->node_cache = rb_ary_new();
|
@@ -655,7 +664,7 @@ noko_xml_document_pin_namespace(xmlNsPtr ns, xmlDocPtr doc)
|
|
655
664
|
|
656
665
|
|
657
666
|
void
|
658
|
-
noko_init_xml_document()
|
667
|
+
noko_init_xml_document(void)
|
659
668
|
{
|
660
669
|
assert(cNokogiriXmlNode);
|
661
670
|
/*
|
data/ext/nokogiri/xml_dtd.c
CHANGED
@@ -44,7 +44,7 @@ entities(VALUE self)
|
|
44
44
|
xmlDtdPtr dtd;
|
45
45
|
VALUE hash;
|
46
46
|
|
47
|
-
|
47
|
+
Noko_Node_Get_Struct(self, xmlDtd, dtd);
|
48
48
|
|
49
49
|
if (!dtd->entities) { return Qnil; }
|
50
50
|
|
@@ -67,7 +67,7 @@ notations(VALUE self)
|
|
67
67
|
xmlDtdPtr dtd;
|
68
68
|
VALUE hash;
|
69
69
|
|
70
|
-
|
70
|
+
Noko_Node_Get_Struct(self, xmlDtd, dtd);
|
71
71
|
|
72
72
|
if (!dtd->notations) { return Qnil; }
|
73
73
|
|
@@ -90,7 +90,7 @@ attributes(VALUE self)
|
|
90
90
|
xmlDtdPtr dtd;
|
91
91
|
VALUE hash;
|
92
92
|
|
93
|
-
|
93
|
+
Noko_Node_Get_Struct(self, xmlDtd, dtd);
|
94
94
|
|
95
95
|
hash = rb_hash_new();
|
96
96
|
|
@@ -113,7 +113,7 @@ elements(VALUE self)
|
|
113
113
|
xmlDtdPtr dtd;
|
114
114
|
VALUE hash;
|
115
115
|
|
116
|
-
|
116
|
+
Noko_Node_Get_Struct(self, xmlDtd, dtd);
|
117
117
|
|
118
118
|
if (!dtd->elements) { return Qnil; }
|
119
119
|
|
@@ -138,8 +138,8 @@ validate(VALUE self, VALUE document)
|
|
138
138
|
xmlValidCtxtPtr ctxt;
|
139
139
|
VALUE error_list;
|
140
140
|
|
141
|
-
|
142
|
-
|
141
|
+
Noko_Node_Get_Struct(self, xmlDtd, dtd);
|
142
|
+
Noko_Node_Get_Struct(document, xmlDoc, doc);
|
143
143
|
error_list = rb_ary_new();
|
144
144
|
|
145
145
|
ctxt = xmlNewValidCtxt();
|
@@ -165,7 +165,7 @@ static VALUE
|
|
165
165
|
system_id(VALUE self)
|
166
166
|
{
|
167
167
|
xmlDtdPtr dtd;
|
168
|
-
|
168
|
+
Noko_Node_Get_Struct(self, xmlDtd, dtd);
|
169
169
|
|
170
170
|
if (!dtd->SystemID) { return Qnil; }
|
171
171
|
|
@@ -182,7 +182,7 @@ static VALUE
|
|
182
182
|
external_id(VALUE self)
|
183
183
|
{
|
184
184
|
xmlDtdPtr dtd;
|
185
|
-
|
185
|
+
Noko_Node_Get_Struct(self, xmlDtd, dtd);
|
186
186
|
|
187
187
|
if (!dtd->ExternalID) { return Qnil; }
|
188
188
|
|
@@ -190,7 +190,7 @@ external_id(VALUE self)
|
|
190
190
|
}
|
191
191
|
|
192
192
|
void
|
193
|
-
noko_init_xml_dtd()
|
193
|
+
noko_init_xml_dtd(void)
|
194
194
|
{
|
195
195
|
assert(cNokogiriXmlNode);
|
196
196
|
/*
|
@@ -31,7 +31,7 @@ get_type(VALUE self)
|
|
31
31
|
xmlElementContentPtr elem;
|
32
32
|
Data_Get_Struct(self, xmlElementContent, elem);
|
33
33
|
|
34
|
-
return INT2NUM(
|
34
|
+
return INT2NUM(elem->type);
|
35
35
|
}
|
36
36
|
|
37
37
|
/*
|
@@ -79,7 +79,7 @@ get_occur(VALUE self)
|
|
79
79
|
xmlElementContentPtr elem;
|
80
80
|
Data_Get_Struct(self, xmlElementContent, elem);
|
81
81
|
|
82
|
-
return INT2NUM(
|
82
|
+
return INT2NUM(elem->ocur);
|
83
83
|
}
|
84
84
|
|
85
85
|
/*
|
@@ -112,7 +112,7 @@ noko_xml_element_content_wrap(VALUE doc, xmlElementContentPtr element)
|
|
112
112
|
}
|
113
113
|
|
114
114
|
void
|
115
|
-
noko_init_xml_element_content()
|
115
|
+
noko_init_xml_element_content(void)
|
116
116
|
{
|
117
117
|
cNokogiriXmlElementContent = rb_define_class_under(mNokogiriXml, "ElementContent", rb_cObject);
|
118
118
|
|
@@ -14,8 +14,8 @@ static VALUE
|
|
14
14
|
element_type(VALUE self)
|
15
15
|
{
|
16
16
|
xmlElementPtr node;
|
17
|
-
|
18
|
-
return INT2NUM(
|
17
|
+
Noko_Node_Get_Struct(self, xmlElement, node);
|
18
|
+
return INT2NUM(node->etype);
|
19
19
|
}
|
20
20
|
|
21
21
|
/*
|
@@ -28,7 +28,7 @@ static VALUE
|
|
28
28
|
content(VALUE self)
|
29
29
|
{
|
30
30
|
xmlElementPtr node;
|
31
|
-
|
31
|
+
Noko_Node_Get_Struct(self, xmlElement, node);
|
32
32
|
|
33
33
|
if (!node->content) { return Qnil; }
|
34
34
|
|
@@ -48,7 +48,7 @@ static VALUE
|
|
48
48
|
prefix(VALUE self)
|
49
49
|
{
|
50
50
|
xmlElementPtr node;
|
51
|
-
|
51
|
+
Noko_Node_Get_Struct(self, xmlElement, node);
|
52
52
|
|
53
53
|
if (!node->prefix) { return Qnil; }
|
54
54
|
|
@@ -56,7 +56,7 @@ prefix(VALUE self)
|
|
56
56
|
}
|
57
57
|
|
58
58
|
void
|
59
|
-
noko_init_xml_element_decl()
|
59
|
+
noko_init_xml_element_decl(void)
|
60
60
|
{
|
61
61
|
assert(cNokogiriXmlNode);
|
62
62
|
cNokogiriXmlElementDecl = rb_define_class_under(mNokogiriXml, "ElementDecl", cNokogiriXmlNode);
|
@@ -45,9 +45,9 @@ rb_xml_encoding_handler_s_delete(VALUE klass, VALUE name)
|
|
45
45
|
|
46
46
|
|
47
47
|
/*
|
48
|
-
* call-seq: Nokogiri::EncodingHandler.alias(
|
48
|
+
* call-seq: Nokogiri::EncodingHandler.alias(real_name, alias_name)
|
49
49
|
*
|
50
|
-
* Alias encoding handler with name +
|
50
|
+
* Alias encoding handler with name +real_name+ to name +alias_name+
|
51
51
|
*/
|
52
52
|
static VALUE
|
53
53
|
rb_xml_encoding_handler_s_alias(VALUE klass, VALUE from, VALUE to)
|
@@ -89,7 +89,7 @@ rb_xml_encoding_handler_name(VALUE self)
|
|
89
89
|
|
90
90
|
|
91
91
|
void
|
92
|
-
noko_init_xml_encoding_handler()
|
92
|
+
noko_init_xml_encoding_handler(void)
|
93
93
|
{
|
94
94
|
cNokogiriEncodingHandler = rb_define_class_under(mNokogiri, "EncodingHandler", rb_cObject);
|
95
95
|
|