nokogiri 1.12.5 → 1.14.3
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 +41 -0
- data/LICENSE-DEPENDENCIES.md +830 -509
- data/LICENSE.md +1 -1
- data/README.md +23 -14
- data/bin/nokogiri +63 -50
- data/dependencies.yml +33 -66
- data/ext/nokogiri/extconf.rb +159 -63
- 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 +3 -9
- 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 +53 -44
- data/ext/nokogiri/xml_document_fragment.c +1 -3
- data/ext/nokogiri/xml_dtd.c +11 -11
- 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 +28 -14
- 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 +982 -396
- data/ext/nokogiri/xml_node_set.c +4 -6
- data/ext/nokogiri/xml_processing_instruction.c +1 -1
- data/ext/nokogiri/xml_reader.c +133 -32
- 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 +11 -9
- 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 +144 -114
- data/ext/nokogiri/xslt_stylesheet.c +122 -23
- 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 -16
- 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/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +9 -8
- data/lib/nokogiri/css/parser.rb +360 -341
- data/lib/nokogiri/css/parser.y +249 -244
- data/lib/nokogiri/css/parser_extras.rb +22 -20
- data/lib/nokogiri/css/syntax_error.rb +1 -0
- data/lib/nokogiri/css/tokenizer.rb +4 -3
- data/lib/nokogiri/css/tokenizer.rex +3 -2
- data/lib/nokogiri/css/xpath_visitor.rb +184 -85
- data/lib/nokogiri/css.rb +44 -6
- data/lib/nokogiri/decorators/slop.rb +8 -7
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +4 -3
- data/lib/nokogiri/gumbo.rb +1 -0
- data/lib/nokogiri/html.rb +16 -10
- data/lib/nokogiri/html4/builder.rb +1 -0
- data/lib/nokogiri/html4/document.rb +56 -164
- data/lib/nokogiri/html4/document_fragment.rb +11 -7
- data/lib/nokogiri/html4/element_description.rb +1 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +432 -532
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/html4/entity_lookup.rb +2 -1
- data/lib/nokogiri/html4/sax/parser.rb +5 -2
- data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
- data/lib/nokogiri/html4.rb +12 -5
- data/lib/nokogiri/html5/document.rb +126 -32
- data/lib/nokogiri/html5/document_fragment.rb +14 -4
- data/lib/nokogiri/html5/node.rb +12 -7
- data/lib/nokogiri/html5.rb +138 -222
- data/lib/nokogiri/jruby/dependencies.rb +2 -19
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/syntax_error.rb +1 -0
- data/lib/nokogiri/version/constant.rb +2 -1
- data/lib/nokogiri/version/info.rb +32 -24
- data/lib/nokogiri/version.rb +1 -0
- data/lib/nokogiri/xml/attr.rb +54 -3
- data/lib/nokogiri/xml/attribute_decl.rb +2 -1
- data/lib/nokogiri/xml/builder.rb +35 -33
- data/lib/nokogiri/xml/cdata.rb +2 -1
- data/lib/nokogiri/xml/character_data.rb +1 -0
- data/lib/nokogiri/xml/document.rb +232 -143
- data/lib/nokogiri/xml/document_fragment.rb +88 -42
- data/lib/nokogiri/xml/dtd.rb +3 -2
- data/lib/nokogiri/xml/element_content.rb +1 -0
- data/lib/nokogiri/xml/element_decl.rb +2 -1
- data/lib/nokogiri/xml/entity_decl.rb +3 -2
- data/lib/nokogiri/xml/entity_reference.rb +1 -0
- data/lib/nokogiri/xml/namespace.rb +44 -0
- data/lib/nokogiri/xml/node/save_options.rb +14 -8
- data/lib/nokogiri/xml/node.rb +708 -383
- data/lib/nokogiri/xml/node_set.rb +134 -59
- data/lib/nokogiri/xml/notation.rb +12 -0
- data/lib/nokogiri/xml/parse_options.rb +140 -56
- data/lib/nokogiri/xml/pp/character_data.rb +8 -6
- data/lib/nokogiri/xml/pp/node.rb +26 -26
- data/lib/nokogiri/xml/pp.rb +1 -0
- data/lib/nokogiri/xml/processing_instruction.rb +3 -1
- data/lib/nokogiri/xml/reader.rb +20 -24
- data/lib/nokogiri/xml/relax_ng.rb +1 -0
- data/lib/nokogiri/xml/sax/document.rb +20 -19
- data/lib/nokogiri/xml/sax/parser.rb +38 -36
- data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
- data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
- data/lib/nokogiri/xml/sax.rb +1 -0
- data/lib/nokogiri/xml/schema.rb +7 -6
- data/lib/nokogiri/xml/searchable.rb +93 -62
- data/lib/nokogiri/xml/syntax_error.rb +5 -4
- data/lib/nokogiri/xml/text.rb +1 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
- data/lib/nokogiri/xml/xpath.rb +12 -0
- data/lib/nokogiri/xml/xpath_context.rb +2 -3
- data/lib/nokogiri/xml.rb +4 -3
- data/lib/nokogiri/xslt/stylesheet.rb +1 -0
- data/lib/nokogiri/xslt.rb +21 -13
- data/lib/nokogiri.rb +22 -27
- data/lib/xsd/xmlparser/nokogiri.rb +28 -25
- data/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2445 -1919
- data/ports/archives/libxml2-2.10.4.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.37.tar.xz +0 -0
- metadata +20 -171
- 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 -2511
- data/patches/libxml2/0007-Fix-XPath-recursion-limit.patch +0 -31
- data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +0 -19
- data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
- data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
@@ -5,13 +5,8 @@ VALUE cNokogiriHtml4SaxParserContext ;
|
|
5
5
|
static void
|
6
6
|
deallocate(xmlParserCtxtPtr ctxt)
|
7
7
|
{
|
8
|
-
NOKOGIRI_DEBUG_START(ctxt);
|
9
|
-
|
10
8
|
ctxt->sax = NULL;
|
11
|
-
|
12
9
|
htmlFreeParserCtxt(ctxt);
|
13
|
-
|
14
|
-
NOKOGIRI_DEBUG_END(ctxt);
|
15
10
|
}
|
16
11
|
|
17
12
|
static VALUE
|
@@ -19,9 +14,8 @@ parse_memory(VALUE klass, VALUE data, VALUE encoding)
|
|
19
14
|
{
|
20
15
|
htmlParserCtxtPtr ctxt;
|
21
16
|
|
22
|
-
|
23
|
-
|
24
|
-
}
|
17
|
+
Check_Type(data, T_STRING);
|
18
|
+
|
25
19
|
if (!(int)RSTRING_LEN(data)) {
|
26
20
|
rb_raise(rb_eRuntimeError, "data cannot be empty");
|
27
21
|
}
|
@@ -107,7 +101,7 @@ parse_with(VALUE self, VALUE sax_handler)
|
|
107
101
|
}
|
108
102
|
|
109
103
|
void
|
110
|
-
noko_init_html_sax_parser_context()
|
104
|
+
noko_init_html_sax_parser_context(void)
|
111
105
|
{
|
112
106
|
assert(cNokogiriXmlSaxParserContext);
|
113
107
|
cNokogiriHtml4SaxParserContext = rb_define_class_under(mNokogiriHtml4Sax, "ParserContext",
|
@@ -85,7 +85,7 @@ initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename,
|
|
85
85
|
}
|
86
86
|
|
87
87
|
void
|
88
|
-
noko_init_html_sax_push_parser()
|
88
|
+
noko_init_html_sax_push_parser(void)
|
89
89
|
{
|
90
90
|
assert(cNokogiriXmlSaxPushParser);
|
91
91
|
cNokogiriHtml4SaxPushParser = rb_define_class_under(mNokogiriHtml4Sax, "PushParser", cNokogiriXmlSaxPushParser);
|
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. */
|
@@ -533,59 +533,68 @@ block_caller(void *ctx, xmlNodePtr c_node, xmlNodePtr c_parent_node)
|
|
533
533
|
static VALUE
|
534
534
|
rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
|
535
535
|
{
|
536
|
-
VALUE
|
537
|
-
VALUE
|
538
|
-
VALUE
|
539
|
-
|
540
|
-
|
536
|
+
VALUE rb_mode;
|
537
|
+
VALUE rb_namespaces;
|
538
|
+
VALUE rb_comments_p;
|
539
|
+
int c_mode = 0;
|
540
|
+
xmlChar **c_namespaces;
|
541
541
|
|
542
|
-
xmlDocPtr
|
543
|
-
xmlOutputBufferPtr
|
544
|
-
xmlC14NIsVisibleCallback
|
545
|
-
void *
|
542
|
+
xmlDocPtr c_doc;
|
543
|
+
xmlOutputBufferPtr c_obuf;
|
544
|
+
xmlC14NIsVisibleCallback c_callback_wrapper = NULL;
|
545
|
+
void *rb_callback = NULL;
|
546
546
|
|
547
547
|
VALUE rb_cStringIO;
|
548
|
-
VALUE
|
548
|
+
VALUE rb_io;
|
549
549
|
|
550
|
-
rb_scan_args(argc, argv, "03", &
|
550
|
+
rb_scan_args(argc, argv, "03", &rb_mode, &rb_namespaces, &rb_comments_p);
|
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
|
+
}
|
551
561
|
|
552
|
-
Data_Get_Struct(self, xmlDoc,
|
562
|
+
Data_Get_Struct(self, xmlDoc, c_doc);
|
553
563
|
|
554
564
|
rb_cStringIO = rb_const_get_at(rb_cObject, rb_intern("StringIO"));
|
555
|
-
|
556
|
-
|
565
|
+
rb_io = rb_class_new_instance(0, 0, rb_cStringIO);
|
566
|
+
c_obuf = xmlAllocOutputBuffer(NULL);
|
557
567
|
|
558
|
-
|
559
|
-
|
560
|
-
|
568
|
+
c_obuf->writecallback = (xmlOutputWriteCallback)noko_io_write;
|
569
|
+
c_obuf->closecallback = (xmlOutputCloseCallback)noko_io_close;
|
570
|
+
c_obuf->context = (void *)rb_io;
|
561
571
|
|
562
572
|
if (rb_block_given_p()) {
|
563
|
-
|
564
|
-
|
573
|
+
c_callback_wrapper = block_caller;
|
574
|
+
rb_callback = (void *)rb_block_proc();
|
565
575
|
}
|
566
576
|
|
567
|
-
if (NIL_P(
|
568
|
-
|
577
|
+
if (NIL_P(rb_namespaces)) {
|
578
|
+
c_namespaces = NULL;
|
569
579
|
} else {
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
ns[i] = (xmlChar *)StringValueCStr(entry);
|
580
|
+
long ns_len = RARRAY_LEN(rb_namespaces);
|
581
|
+
c_namespaces = ruby_xcalloc((size_t)ns_len + 1, sizeof(xmlChar *));
|
582
|
+
for (int j = 0 ; j < ns_len ; j++) {
|
583
|
+
VALUE entry = rb_ary_entry(rb_namespaces, j);
|
584
|
+
c_namespaces[j] = (xmlChar *)StringValueCStr(entry);
|
576
585
|
}
|
577
586
|
}
|
578
587
|
|
588
|
+
xmlC14NExecute(c_doc, c_callback_wrapper, rb_callback,
|
589
|
+
c_mode,
|
590
|
+
c_namespaces,
|
591
|
+
(int)RTEST(rb_comments_p),
|
592
|
+
c_obuf);
|
579
593
|
|
580
|
-
|
581
|
-
|
582
|
-
ns,
|
583
|
-
(int) RTEST(with_comments),
|
584
|
-
buf);
|
585
|
-
|
586
|
-
xmlOutputBufferClose(buf);
|
594
|
+
ruby_xfree(c_namespaces);
|
595
|
+
xmlOutputBufferClose(c_obuf);
|
587
596
|
|
588
|
-
return rb_funcall(
|
597
|
+
return rb_funcall(rb_io, rb_intern("string"), 0);
|
589
598
|
}
|
590
599
|
|
591
600
|
VALUE
|
@@ -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
|
/*
|
@@ -28,13 +28,11 @@ new (int argc, VALUE *argv, VALUE klass)
|
|
28
28
|
rb_node = noko_xml_node_wrap(klass, node);
|
29
29
|
rb_obj_call_init(rb_node, argc, argv);
|
30
30
|
|
31
|
-
if (rb_block_given_p()) { rb_yield(rb_node); }
|
32
|
-
|
33
31
|
return rb_node;
|
34
32
|
}
|
35
33
|
|
36
34
|
void
|
37
|
-
noko_init_xml_document_fragment()
|
35
|
+
noko_init_xml_document_fragment(void)
|
38
36
|
{
|
39
37
|
assert(cNokogiriXmlNode);
|
40
38
|
/*
|
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
|
|
@@ -57,9 +57,9 @@ entities(VALUE self)
|
|
57
57
|
|
58
58
|
/*
|
59
59
|
* call-seq:
|
60
|
-
* notations
|
60
|
+
* notations() → Hash<name(String)⇒Notation>
|
61
61
|
*
|
62
|
-
*
|
62
|
+
* [Returns] All the notations for this DTD in a Hash of Notation +name+ to Notation.
|
63
63
|
*/
|
64
64
|
static VALUE
|
65
65
|
notations(VALUE self)
|
@@ -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
|
/*
|