nokogiri 1.13.5-java → 1.13.8-java
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/ext/java/nokogiri/Html4SaxParserContext.java +11 -0
- data/ext/java/nokogiri/XmlReader.java +8 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +5 -2
- data/ext/java/nokogiri/internals/ParserContext.java +7 -1
- data/ext/java/nokogiri/internals/ReaderNode.java +3 -2
- data/ext/nokogiri/extconf.rb +2 -0
- data/ext/nokogiri/gumbo.c +1 -1
- data/ext/nokogiri/html4_sax_parser_context.c +2 -3
- data/ext/nokogiri/xml_attr.c +2 -2
- data/ext/nokogiri/xml_attribute_decl.c +3 -3
- data/ext/nokogiri/xml_cdata.c +1 -1
- data/ext/nokogiri/xml_document.c +1 -1
- data/ext/nokogiri/xml_dtd.c +8 -8
- data/ext/nokogiri/xml_element_decl.c +3 -3
- data/ext/nokogiri/xml_entity_decl.c +5 -5
- data/ext/nokogiri/xml_node.c +85 -64
- data/ext/nokogiri/xml_node_set.c +4 -4
- data/ext/nokogiri/xml_reader.c +52 -1
- data/ext/nokogiri/xml_sax_parser_context.c +10 -3
- data/ext/nokogiri/xml_schema.c +3 -3
- data/ext/nokogiri/xml_text.c +1 -1
- data/ext/nokogiri/xml_xpath_context.c +1 -1
- data/lib/nokogiri/html4/sax/parser.rb +1 -1
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/xml/reader.rb +6 -8
- metadata +12 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ada61d4741dbf0af27d1f10e368ae64f8f26f22bcd2476d8d7befc163ad49d6c
|
4
|
+
data.tar.gz: 1a6a10073ade74d223c05b9afac779e6ce9aec5db2d105979a21184cc3448fb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1c2231c15b6a945424f161881fa4cd0ca9c50cb3f6cc9c3df0447d7705601ebd816ab9a597f6bb3f7de8382f880e8c0c66829bbc3eef7b0541a90eed53a33c9
|
7
|
+
data.tar.gz: a0830be00451175c4eccefe67eeefc47bfe7ec19adc0e05e2673fb5f80a87f382912c6b90e11e2029c8c7757d8f1eaec81102a76a7bf3f8ea2f55450e3d4dd26
|
@@ -231,6 +231,13 @@ public class Html4SaxParserContext extends XmlSaxParserContext
|
|
231
231
|
IRubyObject data,
|
232
232
|
IRubyObject encoding)
|
233
233
|
{
|
234
|
+
if (!(data instanceof RubyString)) {
|
235
|
+
throw context.getRuntime().newTypeError("data must be kind_of String");
|
236
|
+
}
|
237
|
+
if (!(encoding instanceof RubyString)) {
|
238
|
+
throw context.getRuntime().newTypeError("data must be kind_of String");
|
239
|
+
}
|
240
|
+
|
234
241
|
Html4SaxParserContext ctx = Html4SaxParserContext.newInstance(context.runtime, (RubyClass) klass);
|
235
242
|
ctx.setInputSourceFile(context, data);
|
236
243
|
String javaEncoding = findEncodingName(context, encoding);
|
@@ -247,6 +254,10 @@ public class Html4SaxParserContext extends XmlSaxParserContext
|
|
247
254
|
IRubyObject data,
|
248
255
|
IRubyObject encoding)
|
249
256
|
{
|
257
|
+
if (!(encoding instanceof RubyFixnum)) {
|
258
|
+
throw context.getRuntime().newTypeError("encoding must be kind_of String");
|
259
|
+
}
|
260
|
+
|
250
261
|
Html4SaxParserContext ctx = Html4SaxParserContext.newInstance(context.runtime, (RubyClass) klass);
|
251
262
|
ctx.setIOInputSource(context, data, context.nil);
|
252
263
|
String javaEncoding = findEncodingName(context, encoding);
|
@@ -141,9 +141,17 @@ public class XmlReader extends RubyObject
|
|
141
141
|
public IRubyObject
|
142
142
|
attribute_nodes(ThreadContext context)
|
143
143
|
{
|
144
|
+
context.runtime.getWarnings().warn("Reader#attribute_nodes is deprecated and will be removed in a future version of Nokogiri. Please use Reader#attribute_hash instead.");
|
144
145
|
return currentNode().getAttributesNodes();
|
145
146
|
}
|
146
147
|
|
148
|
+
@JRubyMethod
|
149
|
+
public IRubyObject
|
150
|
+
attribute_hash(ThreadContext context)
|
151
|
+
{
|
152
|
+
return currentNode().getAttributes(context);
|
153
|
+
}
|
154
|
+
|
147
155
|
@JRubyMethod(name = "attributes?")
|
148
156
|
public IRubyObject
|
149
157
|
attributes_p(ThreadContext context)
|
@@ -130,9 +130,12 @@ public class XmlSaxParserContext extends ParserContext
|
|
130
130
|
parse_io(ThreadContext context,
|
131
131
|
IRubyObject klazz,
|
132
132
|
IRubyObject data,
|
133
|
-
IRubyObject
|
133
|
+
IRubyObject encoding)
|
134
134
|
{
|
135
|
-
//
|
135
|
+
// check the type of the unused encoding to match behavior of CRuby
|
136
|
+
if (!(encoding instanceof RubyFixnum)) {
|
137
|
+
throw context.getRuntime().newTypeError("encoding must be kind_of String");
|
138
|
+
}
|
136
139
|
final Ruby runtime = context.runtime;
|
137
140
|
XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
|
138
141
|
ctx.initialize(runtime);
|
@@ -58,6 +58,12 @@ public abstract class ParserContext extends RubyObject
|
|
58
58
|
source = new InputSource();
|
59
59
|
ParserContext.setUrl(context, source, url);
|
60
60
|
|
61
|
+
Ruby ruby = context.getRuntime();
|
62
|
+
|
63
|
+
if (!(data.respondsTo("read"))) {
|
64
|
+
throw ruby.newTypeError("must respond to :read");
|
65
|
+
}
|
66
|
+
|
61
67
|
source.setByteStream(new IOInputStream(data));
|
62
68
|
if (java_encoding != null) {
|
63
69
|
source.setEncoding(java_encoding);
|
@@ -73,7 +79,7 @@ public abstract class ParserContext extends RubyObject
|
|
73
79
|
Ruby ruby = context.getRuntime();
|
74
80
|
|
75
81
|
if (!(data instanceof RubyString)) {
|
76
|
-
throw ruby.
|
82
|
+
throw ruby.newTypeError("must be kind_of String");
|
77
83
|
}
|
78
84
|
|
79
85
|
RubyString stringData = (RubyString) data;
|
@@ -112,9 +112,10 @@ public abstract class ReaderNode
|
|
112
112
|
getAttributes(ThreadContext context)
|
113
113
|
{
|
114
114
|
final Ruby runtime = context.runtime;
|
115
|
-
if (attributeList == null) { return runtime.getNil(); }
|
116
115
|
RubyHash hash = RubyHash.newHash(runtime);
|
116
|
+
if (attributeList == null) { return hash; }
|
117
117
|
for (int i = 0; i < attributeList.length; i++) {
|
118
|
+
if (isNamespace(attributeList.names.get(i))) { continue; }
|
118
119
|
IRubyObject k = stringOrBlank(runtime, attributeList.names.get(i));
|
119
120
|
IRubyObject v = stringOrBlank(runtime, attributeList.values.get(i));
|
120
121
|
hash.fastASetCheckString(runtime, k, v); // hash.op_aset(context, k, v)
|
@@ -150,8 +151,8 @@ public abstract class ReaderNode
|
|
150
151
|
getNamespaces(ThreadContext context)
|
151
152
|
{
|
152
153
|
final Ruby runtime = context.runtime;
|
153
|
-
if (namespaces == null) { return runtime.getNil(); }
|
154
154
|
RubyHash hash = RubyHash.newHash(runtime);
|
155
|
+
if (namespaces == null) { return hash; }
|
155
156
|
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
|
156
157
|
IRubyObject k = stringOrBlank(runtime, entry.getKey());
|
157
158
|
IRubyObject v = stringOrBlank(runtime, entry.getValue());
|
data/ext/nokogiri/extconf.rb
CHANGED
@@ -973,6 +973,8 @@ have_func("xmlRelaxNGSetParserStructuredErrors") # introduced in libxml 2.6.24
|
|
973
973
|
have_func("xmlRelaxNGSetValidStructuredErrors") # introduced in libxml 2.6.21
|
974
974
|
have_func("xmlSchemaSetValidStructuredErrors") # introduced in libxml 2.6.23
|
975
975
|
have_func("xmlSchemaSetParserStructuredErrors") # introduced in libxml 2.6.23
|
976
|
+
have_func("rb_gc_location") # introduced in Ruby 2.7
|
977
|
+
have_func("rb_category_warning") # introduced in Ruby 3.0
|
976
978
|
|
977
979
|
have_func("vasprintf")
|
978
980
|
|
data/ext/nokogiri/gumbo.c
CHANGED
@@ -19,9 +19,8 @@ parse_memory(VALUE klass, VALUE data, VALUE encoding)
|
|
19
19
|
{
|
20
20
|
htmlParserCtxtPtr ctxt;
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
}
|
22
|
+
Check_Type(data, T_STRING);
|
23
|
+
|
25
24
|
if (!(int)RSTRING_LEN(data)) {
|
26
25
|
rb_raise(rb_eRuntimeError, "data cannot be empty");
|
27
26
|
}
|
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,
|
@@ -12,7 +12,7 @@ static VALUE
|
|
12
12
|
attribute_type(VALUE self)
|
13
13
|
{
|
14
14
|
xmlAttributePtr node;
|
15
|
-
|
15
|
+
Noko_Node_Get_Struct(self, xmlAttribute, node);
|
16
16
|
return INT2NUM((long)node->atype);
|
17
17
|
}
|
18
18
|
|
@@ -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;
|
data/ext/nokogiri/xml_cdata.c
CHANGED
@@ -25,7 +25,7 @@ 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);
|
data/ext/nokogiri/xml_document.c
CHANGED
@@ -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. */
|
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
|
|
@@ -14,7 +14,7 @@ static VALUE
|
|
14
14
|
element_type(VALUE self)
|
15
15
|
{
|
16
16
|
xmlElementPtr node;
|
17
|
-
|
17
|
+
Noko_Node_Get_Struct(self, xmlElement, node);
|
18
18
|
return INT2NUM((long)node->etype);
|
19
19
|
}
|
20
20
|
|
@@ -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
|
|
@@ -12,7 +12,7 @@ static VALUE
|
|
12
12
|
original_content(VALUE self)
|
13
13
|
{
|
14
14
|
xmlEntityPtr node;
|
15
|
-
|
15
|
+
Noko_Node_Get_Struct(self, xmlEntity, node);
|
16
16
|
|
17
17
|
if (!node->orig) { return Qnil; }
|
18
18
|
|
@@ -29,7 +29,7 @@ static VALUE
|
|
29
29
|
get_content(VALUE self)
|
30
30
|
{
|
31
31
|
xmlEntityPtr node;
|
32
|
-
|
32
|
+
Noko_Node_Get_Struct(self, xmlEntity, node);
|
33
33
|
|
34
34
|
if (!node->content) { return Qnil; }
|
35
35
|
|
@@ -46,7 +46,7 @@ static VALUE
|
|
46
46
|
entity_type(VALUE self)
|
47
47
|
{
|
48
48
|
xmlEntityPtr node;
|
49
|
-
|
49
|
+
Noko_Node_Get_Struct(self, xmlEntity, node);
|
50
50
|
|
51
51
|
return INT2NUM((int)node->etype);
|
52
52
|
}
|
@@ -61,7 +61,7 @@ static VALUE
|
|
61
61
|
external_id(VALUE self)
|
62
62
|
{
|
63
63
|
xmlEntityPtr node;
|
64
|
-
|
64
|
+
Noko_Node_Get_Struct(self, xmlEntity, node);
|
65
65
|
|
66
66
|
if (!node->ExternalID) { return Qnil; }
|
67
67
|
|
@@ -78,7 +78,7 @@ static VALUE
|
|
78
78
|
system_id(VALUE self)
|
79
79
|
{
|
80
80
|
xmlEntityPtr node;
|
81
|
-
|
81
|
+
Noko_Node_Get_Struct(self, xmlEntity, node);
|
82
82
|
|
83
83
|
if (!node->SystemID) { return Qnil; }
|
84
84
|
|
data/ext/nokogiri/xml_node.c
CHANGED
@@ -7,7 +7,6 @@ static ID id_decorate, id_decorate_bang;
|
|
7
7
|
|
8
8
|
typedef xmlNodePtr(*pivot_reparentee_func)(xmlNodePtr, xmlNodePtr);
|
9
9
|
|
10
|
-
|
11
10
|
#ifdef DEBUG
|
12
11
|
static void
|
13
12
|
_xml_node_dealloc(xmlNodePtr x)
|
@@ -19,10 +18,13 @@ _xml_node_dealloc(xmlNodePtr x)
|
|
19
18
|
# define _xml_node_dealloc 0
|
20
19
|
#endif
|
21
20
|
|
22
|
-
|
23
21
|
static void
|
24
22
|
_xml_node_mark(xmlNodePtr node)
|
25
23
|
{
|
24
|
+
if (!DOC_RUBY_OBJECT_TEST(node->doc)) {
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
|
26
28
|
xmlDocPtr doc = node->doc;
|
27
29
|
if (doc->type == XML_DOCUMENT_NODE || doc->type == XML_HTML_DOCUMENT_NODE) {
|
28
30
|
if (DOC_RUBY_OBJECT_TEST(doc)) {
|
@@ -33,6 +35,31 @@ _xml_node_mark(xmlNodePtr node)
|
|
33
35
|
}
|
34
36
|
}
|
35
37
|
|
38
|
+
#ifdef HAVE_RB_GC_LOCATION
|
39
|
+
static void
|
40
|
+
_xml_node_update_references(xmlNodePtr node)
|
41
|
+
{
|
42
|
+
if (node->_private) {
|
43
|
+
node->_private = (void *)rb_gc_location((VALUE)node->_private);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
#endif
|
47
|
+
|
48
|
+
typedef void (*gc_callback_t)(void *);
|
49
|
+
|
50
|
+
static const rb_data_type_t nokogiri_node_type = {
|
51
|
+
"Nokogiri/XMLNode",
|
52
|
+
{
|
53
|
+
(gc_callback_t)_xml_node_mark, (gc_callback_t)_xml_node_dealloc, 0,
|
54
|
+
#ifdef HAVE_RB_GC_LOCATION
|
55
|
+
(gc_callback_t)_xml_node_update_references
|
56
|
+
#endif
|
57
|
+
},
|
58
|
+
0, 0,
|
59
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
60
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
61
|
+
#endif
|
62
|
+
};
|
36
63
|
|
37
64
|
static void
|
38
65
|
relink_namespace(xmlNodePtr reparented)
|
@@ -198,8 +225,8 @@ reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_reparentee_func
|
|
198
225
|
rb_raise(rb_eArgError, "node must be a Nokogiri::XML::Node");
|
199
226
|
}
|
200
227
|
|
201
|
-
|
202
|
-
|
228
|
+
Noko_Node_Get_Struct(reparentee_obj, xmlNode, reparentee);
|
229
|
+
Noko_Node_Get_Struct(pivot_obj, xmlNode, pivot);
|
203
230
|
|
204
231
|
/*
|
205
232
|
* Check if nodes given are appropriate to have a parent-child
|
@@ -439,7 +466,7 @@ rb_xml_node_add_namespace_definition(VALUE rb_node, VALUE rb_prefix, VALUE rb_hr
|
|
439
466
|
xmlNsPtr c_namespace;
|
440
467
|
const xmlChar *c_prefix = (const xmlChar *)(NIL_P(rb_prefix) ? NULL : StringValueCStr(rb_prefix));
|
441
468
|
|
442
|
-
|
469
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
|
443
470
|
element = c_node ;
|
444
471
|
|
445
472
|
c_namespace = xmlSearchNs(c_node->doc, c_node, c_prefix);
|
@@ -506,7 +533,7 @@ rb_xml_node_attribute(VALUE self, VALUE name)
|
|
506
533
|
{
|
507
534
|
xmlNodePtr node;
|
508
535
|
xmlAttrPtr prop;
|
509
|
-
|
536
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
510
537
|
prop = xmlHasProp(node, (xmlChar *)StringValueCStr(name));
|
511
538
|
|
512
539
|
if (! prop) { return Qnil; }
|
@@ -557,7 +584,7 @@ rb_xml_node_attribute_nodes(VALUE rb_node)
|
|
557
584
|
{
|
558
585
|
xmlNodePtr c_node;
|
559
586
|
|
560
|
-
|
587
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
|
561
588
|
|
562
589
|
return noko_xml_node_attrs(c_node);
|
563
590
|
}
|
@@ -609,7 +636,7 @@ rb_xml_node_attribute_with_ns(VALUE self, VALUE name, VALUE namespace)
|
|
609
636
|
{
|
610
637
|
xmlNodePtr node;
|
611
638
|
xmlAttrPtr prop;
|
612
|
-
|
639
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
613
640
|
prop = xmlHasNsProp(node, (xmlChar *)StringValueCStr(name),
|
614
641
|
NIL_P(namespace) ? NULL : (xmlChar *)StringValueCStr(namespace));
|
615
642
|
|
@@ -636,7 +663,7 @@ static VALUE
|
|
636
663
|
rb_xml_node_blank_eh(VALUE self)
|
637
664
|
{
|
638
665
|
xmlNodePtr node;
|
639
|
-
|
666
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
640
667
|
return (1 == xmlIsBlankNode(node)) ? Qtrue : Qfalse ;
|
641
668
|
}
|
642
669
|
|
@@ -658,7 +685,7 @@ static VALUE
|
|
658
685
|
rb_xml_node_child(VALUE self)
|
659
686
|
{
|
660
687
|
xmlNodePtr node, child;
|
661
|
-
|
688
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
662
689
|
|
663
690
|
child = node->children;
|
664
691
|
if (!child) { return Qnil; }
|
@@ -683,7 +710,7 @@ rb_xml_node_children(VALUE self)
|
|
683
710
|
VALUE document;
|
684
711
|
VALUE node_set;
|
685
712
|
|
686
|
-
|
713
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
687
714
|
|
688
715
|
child = node->children;
|
689
716
|
set = xmlXPathNodeSetCreate(child);
|
@@ -742,7 +769,7 @@ rb_xml_node_content(VALUE self)
|
|
742
769
|
xmlNodePtr node;
|
743
770
|
xmlChar *content;
|
744
771
|
|
745
|
-
|
772
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
746
773
|
|
747
774
|
content = xmlNodeGetContent(node);
|
748
775
|
if (content) {
|
@@ -765,7 +792,7 @@ static VALUE
|
|
765
792
|
rb_xml_node_document(VALUE self)
|
766
793
|
{
|
767
794
|
xmlNodePtr node;
|
768
|
-
|
795
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
769
796
|
return DOC_RUBY_OBJECT(node->doc);
|
770
797
|
}
|
771
798
|
|
@@ -780,7 +807,7 @@ static VALUE
|
|
780
807
|
rb_xml_node_pointer_id(VALUE self)
|
781
808
|
{
|
782
809
|
xmlNodePtr node;
|
783
|
-
|
810
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
784
811
|
|
785
812
|
return INT2NUM((long)(node));
|
786
813
|
}
|
@@ -797,7 +824,7 @@ encode_special_chars(VALUE self, VALUE string)
|
|
797
824
|
xmlChar *encoded;
|
798
825
|
VALUE encoded_str;
|
799
826
|
|
800
|
-
|
827
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
801
828
|
encoded = xmlEncodeSpecialChars(
|
802
829
|
node->doc,
|
803
830
|
(const xmlChar *)StringValueCStr(string)
|
@@ -828,7 +855,7 @@ create_internal_subset(VALUE self, VALUE name, VALUE external_id, VALUE system_i
|
|
828
855
|
xmlDocPtr doc;
|
829
856
|
xmlDtdPtr dtd;
|
830
857
|
|
831
|
-
|
858
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
832
859
|
|
833
860
|
doc = node->doc;
|
834
861
|
|
@@ -861,7 +888,7 @@ create_external_subset(VALUE self, VALUE name, VALUE external_id, VALUE system_i
|
|
861
888
|
xmlDocPtr doc;
|
862
889
|
xmlDtdPtr dtd;
|
863
890
|
|
864
|
-
|
891
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
865
892
|
|
866
893
|
doc = node->doc;
|
867
894
|
|
@@ -894,7 +921,7 @@ external_subset(VALUE self)
|
|
894
921
|
xmlDocPtr doc;
|
895
922
|
xmlDtdPtr dtd;
|
896
923
|
|
897
|
-
|
924
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
898
925
|
|
899
926
|
if (!node->doc) { return Qnil; }
|
900
927
|
|
@@ -919,7 +946,7 @@ internal_subset(VALUE self)
|
|
919
946
|
xmlDocPtr doc;
|
920
947
|
xmlDtdPtr dtd;
|
921
948
|
|
922
|
-
|
949
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
923
950
|
|
924
951
|
if (!node->doc) { return Qnil; }
|
925
952
|
|
@@ -955,7 +982,7 @@ duplicate_node(int argc, VALUE *argv, VALUE self)
|
|
955
982
|
xmlDocPtr new_parent_doc;
|
956
983
|
xmlNodePtr node, dup;
|
957
984
|
|
958
|
-
|
985
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
959
986
|
|
960
987
|
n_args = rb_scan_args(argc, argv, "02", &r_level, &r_new_parent_doc);
|
961
988
|
|
@@ -988,7 +1015,7 @@ static VALUE
|
|
988
1015
|
unlink_node(VALUE self)
|
989
1016
|
{
|
990
1017
|
xmlNodePtr node;
|
991
|
-
|
1018
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
992
1019
|
xmlUnlinkNode(node);
|
993
1020
|
noko_xml_document_pin_node(node);
|
994
1021
|
return self;
|
@@ -1005,7 +1032,7 @@ static VALUE
|
|
1005
1032
|
next_sibling(VALUE self)
|
1006
1033
|
{
|
1007
1034
|
xmlNodePtr node, sibling;
|
1008
|
-
|
1035
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1009
1036
|
|
1010
1037
|
sibling = node->next;
|
1011
1038
|
if (!sibling) { return Qnil; }
|
@@ -1023,7 +1050,7 @@ static VALUE
|
|
1023
1050
|
previous_sibling(VALUE self)
|
1024
1051
|
{
|
1025
1052
|
xmlNodePtr node, sibling;
|
1026
|
-
|
1053
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1027
1054
|
|
1028
1055
|
sibling = node->prev;
|
1029
1056
|
if (!sibling) { return Qnil; }
|
@@ -1041,7 +1068,7 @@ static VALUE
|
|
1041
1068
|
next_element(VALUE self)
|
1042
1069
|
{
|
1043
1070
|
xmlNodePtr node, sibling;
|
1044
|
-
|
1071
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1045
1072
|
|
1046
1073
|
sibling = xmlNextElementSibling(node);
|
1047
1074
|
if (!sibling) { return Qnil; }
|
@@ -1059,7 +1086,7 @@ static VALUE
|
|
1059
1086
|
previous_element(VALUE self)
|
1060
1087
|
{
|
1061
1088
|
xmlNodePtr node, sibling;
|
1062
|
-
|
1089
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1063
1090
|
|
1064
1091
|
/*
|
1065
1092
|
* note that we don't use xmlPreviousElementSibling here because it's buggy pre-2.7.7.
|
@@ -1081,7 +1108,7 @@ replace(VALUE self, VALUE new_node)
|
|
1081
1108
|
VALUE reparent = reparent_node_with(self, new_node, xmlReplaceNodeWrapper);
|
1082
1109
|
|
1083
1110
|
xmlNodePtr pivot;
|
1084
|
-
|
1111
|
+
Noko_Node_Get_Struct(self, xmlNode, pivot);
|
1085
1112
|
noko_xml_document_pin_node(pivot);
|
1086
1113
|
|
1087
1114
|
return reparent;
|
@@ -1116,7 +1143,7 @@ rb_xml_node_element_children(VALUE self)
|
|
1116
1143
|
VALUE document;
|
1117
1144
|
VALUE node_set;
|
1118
1145
|
|
1119
|
-
|
1146
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1120
1147
|
|
1121
1148
|
child = xmlFirstElementChild(node);
|
1122
1149
|
set = xmlXPathNodeSetCreate(child);
|
@@ -1155,7 +1182,7 @@ static VALUE
|
|
1155
1182
|
rb_xml_node_first_element_child(VALUE self)
|
1156
1183
|
{
|
1157
1184
|
xmlNodePtr node, child;
|
1158
|
-
|
1185
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1159
1186
|
|
1160
1187
|
child = xmlFirstElementChild(node);
|
1161
1188
|
if (!child) { return Qnil; }
|
@@ -1182,7 +1209,7 @@ static VALUE
|
|
1182
1209
|
rb_xml_node_last_element_child(VALUE self)
|
1183
1210
|
{
|
1184
1211
|
xmlNodePtr node, child;
|
1185
|
-
|
1212
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1186
1213
|
|
1187
1214
|
child = xmlLastElementChild(node);
|
1188
1215
|
if (!child) { return Qnil; }
|
@@ -1200,7 +1227,7 @@ static VALUE
|
|
1200
1227
|
key_eh(VALUE self, VALUE attribute)
|
1201
1228
|
{
|
1202
1229
|
xmlNodePtr node;
|
1203
|
-
|
1230
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1204
1231
|
if (xmlHasProp(node, (xmlChar *)StringValueCStr(attribute))) {
|
1205
1232
|
return Qtrue;
|
1206
1233
|
}
|
@@ -1217,7 +1244,7 @@ static VALUE
|
|
1217
1244
|
namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
|
1218
1245
|
{
|
1219
1246
|
xmlNodePtr node;
|
1220
|
-
|
1247
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1221
1248
|
if (xmlHasNsProp(node, (xmlChar *)StringValueCStr(attribute),
|
1222
1249
|
NIL_P(namespace) ? NULL : (xmlChar *)StringValueCStr(namespace))) {
|
1223
1250
|
return Qtrue;
|
@@ -1236,7 +1263,7 @@ set(VALUE self, VALUE property, VALUE value)
|
|
1236
1263
|
{
|
1237
1264
|
xmlNodePtr node, cur;
|
1238
1265
|
xmlAttrPtr prop;
|
1239
|
-
|
1266
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1240
1267
|
|
1241
1268
|
/* If a matching attribute node already exists, then xmlSetProp will destroy
|
1242
1269
|
* the existing node's children. However, if Nokogiri has a node object
|
@@ -1281,7 +1308,7 @@ get(VALUE self, VALUE rattribute)
|
|
1281
1308
|
|
1282
1309
|
if (NIL_P(rattribute)) { return Qnil; }
|
1283
1310
|
|
1284
|
-
|
1311
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1285
1312
|
attribute = xmlCharStrdup(StringValueCStr(rattribute));
|
1286
1313
|
|
1287
1314
|
colon = DISCARD_CONST_QUAL_XMLCHAR(xmlStrchr(attribute, (const xmlChar)':'));
|
@@ -1323,7 +1350,7 @@ set_namespace(VALUE self, VALUE namespace)
|
|
1323
1350
|
xmlNodePtr node;
|
1324
1351
|
xmlNsPtr ns = NULL;
|
1325
1352
|
|
1326
|
-
|
1353
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1327
1354
|
|
1328
1355
|
if (!NIL_P(namespace)) {
|
1329
1356
|
Data_Get_Struct(namespace, xmlNs, ns);
|
@@ -1360,7 +1387,7 @@ static VALUE
|
|
1360
1387
|
rb_xml_node_namespace(VALUE rb_node)
|
1361
1388
|
{
|
1362
1389
|
xmlNodePtr c_node ;
|
1363
|
-
|
1390
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
|
1364
1391
|
|
1365
1392
|
if (c_node->ns) {
|
1366
1393
|
return noko_xml_namespace_wrap(c_node->ns, c_node->doc);
|
@@ -1405,7 +1432,7 @@ namespace_definitions(VALUE rb_node)
|
|
1405
1432
|
xmlNsPtr c_namespace;
|
1406
1433
|
VALUE definitions = rb_ary_new();
|
1407
1434
|
|
1408
|
-
|
1435
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
|
1409
1436
|
|
1410
1437
|
c_namespace = c_node->nsDef;
|
1411
1438
|
if (!c_namespace) {
|
@@ -1456,7 +1483,7 @@ rb_xml_node_namespace_scopes(VALUE rb_node)
|
|
1456
1483
|
VALUE scopes = rb_ary_new();
|
1457
1484
|
int j;
|
1458
1485
|
|
1459
|
-
|
1486
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
|
1460
1487
|
|
1461
1488
|
namespaces = xmlGetNsList(c_node->doc, c_node);
|
1462
1489
|
if (!namespaces) {
|
@@ -1481,7 +1508,7 @@ static VALUE
|
|
1481
1508
|
node_type(VALUE self)
|
1482
1509
|
{
|
1483
1510
|
xmlNodePtr node;
|
1484
|
-
|
1511
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1485
1512
|
return INT2NUM((long)node->type);
|
1486
1513
|
}
|
1487
1514
|
|
@@ -1495,7 +1522,7 @@ static VALUE
|
|
1495
1522
|
set_native_content(VALUE self, VALUE content)
|
1496
1523
|
{
|
1497
1524
|
xmlNodePtr node, child, next ;
|
1498
|
-
|
1525
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1499
1526
|
|
1500
1527
|
child = node->children;
|
1501
1528
|
while (NULL != child) {
|
@@ -1521,7 +1548,7 @@ set_lang(VALUE self_rb, VALUE lang_rb)
|
|
1521
1548
|
xmlNodePtr self ;
|
1522
1549
|
xmlChar *lang ;
|
1523
1550
|
|
1524
|
-
|
1551
|
+
Noko_Node_Get_Struct(self_rb, xmlNode, self);
|
1525
1552
|
lang = (xmlChar *)StringValueCStr(lang_rb);
|
1526
1553
|
|
1527
1554
|
xmlNodeSetLang(self, lang);
|
@@ -1543,7 +1570,7 @@ get_lang(VALUE self_rb)
|
|
1543
1570
|
xmlChar *lang ;
|
1544
1571
|
VALUE lang_rb ;
|
1545
1572
|
|
1546
|
-
|
1573
|
+
Noko_Node_Get_Struct(self_rb, xmlNode, self);
|
1547
1574
|
|
1548
1575
|
lang = xmlNodeGetLang(self);
|
1549
1576
|
if (lang) {
|
@@ -1572,7 +1599,7 @@ static VALUE
|
|
1572
1599
|
get_parent(VALUE self)
|
1573
1600
|
{
|
1574
1601
|
xmlNodePtr node, parent;
|
1575
|
-
|
1602
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1576
1603
|
|
1577
1604
|
parent = node->parent;
|
1578
1605
|
if (!parent) { return Qnil; }
|
@@ -1590,7 +1617,7 @@ static VALUE
|
|
1590
1617
|
set_name(VALUE self, VALUE new_name)
|
1591
1618
|
{
|
1592
1619
|
xmlNodePtr node;
|
1593
|
-
|
1620
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1594
1621
|
xmlNodeSetName(node, (xmlChar *)StringValueCStr(new_name));
|
1595
1622
|
return new_name;
|
1596
1623
|
}
|
@@ -1605,7 +1632,7 @@ static VALUE
|
|
1605
1632
|
get_name(VALUE self)
|
1606
1633
|
{
|
1607
1634
|
xmlNodePtr node;
|
1608
|
-
|
1635
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1609
1636
|
if (node->name) {
|
1610
1637
|
return NOKOGIRI_STR_NEW2(node->name);
|
1611
1638
|
}
|
@@ -1625,7 +1652,7 @@ rb_xml_node_path(VALUE rb_node)
|
|
1625
1652
|
xmlChar *c_path ;
|
1626
1653
|
VALUE rval;
|
1627
1654
|
|
1628
|
-
|
1655
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
|
1629
1656
|
|
1630
1657
|
c_path = xmlGetNodePath(c_node);
|
1631
1658
|
if (c_path == NULL) {
|
@@ -1674,7 +1701,7 @@ native_write_to(
|
|
1674
1701
|
const char *before_indent;
|
1675
1702
|
xmlSaveCtxtPtr savectx;
|
1676
1703
|
|
1677
|
-
|
1704
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1678
1705
|
|
1679
1706
|
xmlIndentTreeOutput = 1;
|
1680
1707
|
|
@@ -1728,7 +1755,7 @@ static VALUE
|
|
1728
1755
|
rb_xml_node_line(VALUE rb_node)
|
1729
1756
|
{
|
1730
1757
|
xmlNodePtr c_node;
|
1731
|
-
|
1758
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
|
1732
1759
|
|
1733
1760
|
return INT2NUM(xmlGetLineNo(c_node));
|
1734
1761
|
}
|
@@ -1745,7 +1772,7 @@ rb_xml_node_line_set(VALUE rb_node, VALUE rb_line_number)
|
|
1745
1772
|
xmlNodePtr c_node;
|
1746
1773
|
int line_number = NUM2INT(rb_line_number);
|
1747
1774
|
|
1748
|
-
|
1775
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
|
1749
1776
|
|
1750
1777
|
// libxml2 optionally uses xmlNode.psvi to store longer line numbers, but only for text nodes.
|
1751
1778
|
// search for "psvi" in SAX2.c and tree.c to learn more.
|
@@ -1779,9 +1806,9 @@ rb_xml_node_new(int argc, VALUE *argv, VALUE klass)
|
|
1779
1806
|
}
|
1780
1807
|
if (!rb_obj_is_kind_of(rb_document_node, cNokogiriXmlDocument)) {
|
1781
1808
|
// TODO: deprecate allowing Node
|
1782
|
-
|
1809
|
+
NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in a future release of Nokogiri.");
|
1783
1810
|
}
|
1784
|
-
|
1811
|
+
Noko_Node_Get_Struct(rb_document_node, xmlNode, c_document_node);
|
1785
1812
|
|
1786
1813
|
c_node = xmlNewNode(NULL, (xmlChar *)StringValueCStr(rb_name));
|
1787
1814
|
c_node->doc = c_document_node->doc;
|
@@ -1811,7 +1838,7 @@ dump_html(VALUE self)
|
|
1811
1838
|
xmlNodePtr node ;
|
1812
1839
|
VALUE html;
|
1813
1840
|
|
1814
|
-
|
1841
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1815
1842
|
|
1816
1843
|
buf = xmlBufferCreate() ;
|
1817
1844
|
htmlNodeDump(buf, node->doc, node);
|
@@ -1830,8 +1857,8 @@ static VALUE
|
|
1830
1857
|
compare(VALUE self, VALUE _other)
|
1831
1858
|
{
|
1832
1859
|
xmlNodePtr node, other;
|
1833
|
-
|
1834
|
-
|
1860
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1861
|
+
Noko_Node_Get_Struct(_other, xmlNode, other);
|
1835
1862
|
|
1836
1863
|
return INT2NUM((long)xmlXPathCmpNodes(other, node));
|
1837
1864
|
}
|
@@ -1851,7 +1878,7 @@ process_xincludes(VALUE self, VALUE options)
|
|
1851
1878
|
xmlNodePtr node;
|
1852
1879
|
VALUE error_list = rb_ary_new();
|
1853
1880
|
|
1854
|
-
|
1881
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1855
1882
|
|
1856
1883
|
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
1857
1884
|
rcode = xmlXIncludeProcessTreeFlags(node, (int)NUM2INT(options));
|
@@ -1882,7 +1909,7 @@ in_context(VALUE self, VALUE _str, VALUE _options)
|
|
1882
1909
|
VALUE doc, err;
|
1883
1910
|
int doc_is_empty;
|
1884
1911
|
|
1885
|
-
|
1912
|
+
Noko_Node_Get_Struct(self, xmlNode, node);
|
1886
1913
|
|
1887
1914
|
doc = DOC_RUBY_OBJECT(node->doc);
|
1888
1915
|
err = rb_iv_get(doc, "@errors");
|
@@ -1974,14 +2001,12 @@ in_context(VALUE self, VALUE _str, VALUE _options)
|
|
1974
2001
|
return noko_xml_node_set_wrap(set, doc);
|
1975
2002
|
}
|
1976
2003
|
|
1977
|
-
|
1978
2004
|
VALUE
|
1979
2005
|
noko_xml_node_wrap(VALUE rb_class, xmlNodePtr c_node)
|
1980
2006
|
{
|
1981
2007
|
VALUE rb_document, rb_node_cache, rb_node;
|
1982
2008
|
nokogiriTuplePtr node_has_a_document;
|
1983
2009
|
xmlDocPtr c_doc;
|
1984
|
-
void (*f_mark)(xmlNodePtr) = NULL ;
|
1985
2010
|
|
1986
2011
|
assert(c_node);
|
1987
2012
|
|
@@ -1989,11 +2014,9 @@ noko_xml_node_wrap(VALUE rb_class, xmlNodePtr c_node)
|
|
1989
2014
|
return DOC_RUBY_OBJECT(c_node->doc);
|
1990
2015
|
}
|
1991
2016
|
|
1992
|
-
/* It's OK if the node doesn't have a fully-realized document (as in XML::Reader). */
|
1993
|
-
/* see https://github.com/sparklemotion/nokogiri/issues/95 */
|
1994
|
-
/* and https://github.com/sparklemotion/nokogiri/issues/439 */
|
1995
2017
|
c_doc = c_node->doc;
|
1996
|
-
|
2018
|
+
|
2019
|
+
// Nodes yielded from XML::Reader don't have a fully-realized Document
|
1997
2020
|
node_has_a_document = DOC_RUBY_OBJECT_TEST(c_doc);
|
1998
2021
|
|
1999
2022
|
if (c_node->_private && node_has_a_document) {
|
@@ -2043,9 +2066,7 @@ noko_xml_node_wrap(VALUE rb_class, xmlNodePtr c_node)
|
|
2043
2066
|
}
|
2044
2067
|
}
|
2045
2068
|
|
2046
|
-
|
2047
|
-
|
2048
|
-
rb_node = Data_Wrap_Struct(rb_class, f_mark, _xml_node_dealloc, c_node) ;
|
2069
|
+
rb_node = TypedData_Wrap_Struct(rb_class, &nokogiri_node_type, c_node) ;
|
2049
2070
|
c_node->_private = (void *)rb_node;
|
2050
2071
|
|
2051
2072
|
if (node_has_a_document) {
|
data/ext/nokogiri/xml_node_set.c
CHANGED
@@ -156,7 +156,7 @@ push(VALUE self, VALUE rb_node)
|
|
156
156
|
Check_Node_Set_Node_Type(rb_node);
|
157
157
|
|
158
158
|
Data_Get_Struct(self, xmlNodeSet, node_set);
|
159
|
-
|
159
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, node);
|
160
160
|
|
161
161
|
xmlXPathNodeSetAdd(node_set, node);
|
162
162
|
|
@@ -179,7 +179,7 @@ delete (VALUE self, VALUE rb_node)
|
|
179
179
|
Check_Node_Set_Node_Type(rb_node);
|
180
180
|
|
181
181
|
Data_Get_Struct(self, xmlNodeSet, node_set);
|
182
|
-
|
182
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, node);
|
183
183
|
|
184
184
|
if (xmlXPathNodeSetContains(node_set, node)) {
|
185
185
|
xpath_node_set_del(node_set, node);
|
@@ -228,7 +228,7 @@ include_eh(VALUE self, VALUE rb_node)
|
|
228
228
|
Check_Node_Set_Node_Type(rb_node);
|
229
229
|
|
230
230
|
Data_Get_Struct(self, xmlNodeSet, node_set);
|
231
|
-
|
231
|
+
Noko_Node_Get_Struct(rb_node, xmlNode, node);
|
232
232
|
|
233
233
|
return (xmlXPathNodeSetContains(node_set, node) ? Qtrue : Qfalse);
|
234
234
|
}
|
@@ -430,7 +430,7 @@ unlink_nodeset(VALUE self)
|
|
430
430
|
xmlNodePtr node_ptr;
|
431
431
|
node = noko_xml_node_wrap(Qnil, node_set->nodeTab[j]);
|
432
432
|
rb_funcall(node, rb_intern("unlink"), 0); /* modifies the C struct out from under the object */
|
433
|
-
|
433
|
+
Noko_Node_Get_Struct(node, xmlNode, node_ptr);
|
434
434
|
node_set->nodeTab[j] = node_ptr ;
|
435
435
|
}
|
436
436
|
}
|
data/ext/nokogiri/xml_reader.c
CHANGED
@@ -31,6 +31,7 @@ has_attributes(xmlTextReaderPtr reader)
|
|
31
31
|
return (0);
|
32
32
|
}
|
33
33
|
|
34
|
+
// TODO: merge this function into the `namespaces` method implementation
|
34
35
|
static void
|
35
36
|
Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
|
36
37
|
{
|
@@ -150,7 +151,11 @@ namespaces(VALUE self)
|
|
150
151
|
/*
|
151
152
|
:call-seq: attribute_nodes() → Array<Nokogiri::XML::Attr>
|
152
153
|
|
153
|
-
Get the attributes of the current node as an Array of Attr
|
154
|
+
Get the attributes of the current node as an Array of XML:Attr
|
155
|
+
|
156
|
+
⚠ This method is deprecated and unsafe to use. It will be removed in a future version of Nokogiri.
|
157
|
+
|
158
|
+
See related: #attribute_hash, #attributes
|
154
159
|
*/
|
155
160
|
static VALUE
|
156
161
|
rb_xml_reader_attribute_nodes(VALUE rb_reader)
|
@@ -160,6 +165,10 @@ rb_xml_reader_attribute_nodes(VALUE rb_reader)
|
|
160
165
|
VALUE attr_nodes;
|
161
166
|
int j;
|
162
167
|
|
168
|
+
// TODO: deprecated, remove in Nokogiri v1.15, see https://github.com/sparklemotion/nokogiri/issues/2598
|
169
|
+
// After removal, we can also remove all the "node_has_a_document" special handling from xml_node.c
|
170
|
+
NOKO_WARN_DEPRECATION("Reader#attribute_nodes is deprecated and will be removed in a future version of Nokogiri. Please use Reader#attribute_hash instead.");
|
171
|
+
|
163
172
|
Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
|
164
173
|
|
165
174
|
if (! has_attributes(c_reader)) {
|
@@ -181,6 +190,47 @@ rb_xml_reader_attribute_nodes(VALUE rb_reader)
|
|
181
190
|
return attr_nodes;
|
182
191
|
}
|
183
192
|
|
193
|
+
/*
|
194
|
+
:call-seq: attribute_hash() → Hash<String ⇒ String>
|
195
|
+
|
196
|
+
Get the attributes of the current node as a Hash of names and values.
|
197
|
+
|
198
|
+
See related: #attributes and #namespaces
|
199
|
+
*/
|
200
|
+
static VALUE
|
201
|
+
rb_xml_reader_attribute_hash(VALUE rb_reader)
|
202
|
+
{
|
203
|
+
VALUE rb_attributes = rb_hash_new();
|
204
|
+
xmlTextReaderPtr c_reader;
|
205
|
+
xmlNodePtr c_node;
|
206
|
+
xmlAttrPtr c_property;
|
207
|
+
|
208
|
+
Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
|
209
|
+
|
210
|
+
if (!has_attributes(c_reader)) {
|
211
|
+
return rb_attributes;
|
212
|
+
}
|
213
|
+
|
214
|
+
c_node = xmlTextReaderExpand(c_reader);
|
215
|
+
c_property = c_node->properties;
|
216
|
+
while (c_property != NULL) {
|
217
|
+
VALUE rb_name = NOKOGIRI_STR_NEW2(c_property->name);
|
218
|
+
VALUE rb_value = Qnil;
|
219
|
+
xmlChar *c_value = xmlNodeGetContent((xmlNode *)c_property);
|
220
|
+
|
221
|
+
if (c_value) {
|
222
|
+
rb_value = NOKOGIRI_STR_NEW2(c_value);
|
223
|
+
xmlFree(c_value);
|
224
|
+
}
|
225
|
+
|
226
|
+
rb_hash_aset(rb_attributes, rb_name, rb_value);
|
227
|
+
|
228
|
+
c_property = c_property->next;
|
229
|
+
}
|
230
|
+
|
231
|
+
return rb_attributes;
|
232
|
+
}
|
233
|
+
|
184
234
|
/*
|
185
235
|
* call-seq:
|
186
236
|
* attribute_at(index)
|
@@ -696,6 +746,7 @@ noko_init_xml_reader()
|
|
696
746
|
rb_define_method(cNokogiriXmlReader, "attribute_at", attribute_at, 1);
|
697
747
|
rb_define_method(cNokogiriXmlReader, "attribute_count", attribute_count, 0);
|
698
748
|
rb_define_method(cNokogiriXmlReader, "attribute_nodes", rb_xml_reader_attribute_nodes, 0);
|
749
|
+
rb_define_method(cNokogiriXmlReader, "attribute_hash", rb_xml_reader_attribute_hash, 0);
|
699
750
|
rb_define_method(cNokogiriXmlReader, "attributes?", attributes_eh, 0);
|
700
751
|
rb_define_method(cNokogiriXmlReader, "base_uri", rb_xml_reader_base_uri, 0);
|
701
752
|
rb_define_method(cNokogiriXmlReader, "default?", default_eh, 0);
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
VALUE cNokogiriXmlSaxParserContext ;
|
4
4
|
|
5
|
+
static ID id_read;
|
6
|
+
|
5
7
|
static void
|
6
8
|
deallocate(xmlParserCtxtPtr ctxt)
|
7
9
|
{
|
@@ -26,6 +28,10 @@ parse_io(VALUE klass, VALUE io, VALUE encoding)
|
|
26
28
|
xmlParserCtxtPtr ctxt;
|
27
29
|
xmlCharEncoding enc = (xmlCharEncoding)NUM2INT(encoding);
|
28
30
|
|
31
|
+
if (!rb_respond_to(io, id_read)) {
|
32
|
+
rb_raise(rb_eTypeError, "argument expected to respond to :read");
|
33
|
+
}
|
34
|
+
|
29
35
|
ctxt = xmlCreateIOParserCtxt(NULL, NULL,
|
30
36
|
(xmlInputReadCallback)noko_io_read,
|
31
37
|
(xmlInputCloseCallback)noko_io_close,
|
@@ -62,9 +68,8 @@ parse_memory(VALUE klass, VALUE data)
|
|
62
68
|
{
|
63
69
|
xmlParserCtxtPtr ctxt;
|
64
70
|
|
65
|
-
|
66
|
-
|
67
|
-
}
|
71
|
+
Check_Type(data, T_STRING);
|
72
|
+
|
68
73
|
if (!(int)RSTRING_LEN(data)) {
|
69
74
|
rb_raise(rb_eRuntimeError, "data cannot be empty");
|
70
75
|
}
|
@@ -278,4 +283,6 @@ noko_init_xml_sax_parser_context()
|
|
278
283
|
rb_define_method(cNokogiriXmlSaxParserContext, "recovery", get_recovery, 0);
|
279
284
|
rb_define_method(cNokogiriXmlSaxParserContext, "line", line, 0);
|
280
285
|
rb_define_method(cNokogiriXmlSaxParserContext, "column", column, 0);
|
286
|
+
|
287
|
+
id_read = rb_intern("read");
|
281
288
|
}
|
data/ext/nokogiri/xml_schema.c
CHANGED
@@ -25,7 +25,7 @@ validate_document(VALUE self, VALUE document)
|
|
25
25
|
VALUE errors;
|
26
26
|
|
27
27
|
Data_Get_Struct(self, xmlSchema, schema);
|
28
|
-
|
28
|
+
Noko_Node_Get_Struct(document, xmlDoc, doc);
|
29
29
|
|
30
30
|
errors = rb_ary_new();
|
31
31
|
|
@@ -179,7 +179,7 @@ has_blank_nodes_p(VALUE cache)
|
|
179
179
|
for (i = 0; i < RARRAY_LEN(cache); i++) {
|
180
180
|
xmlNodePtr node;
|
181
181
|
VALUE element = rb_ary_entry(cache, i);
|
182
|
-
|
182
|
+
Noko_Node_Get_Struct(element, xmlNode, node);
|
183
183
|
if (xmlIsBlankNode(node)) {
|
184
184
|
return 1;
|
185
185
|
}
|
@@ -210,7 +210,7 @@ from_document(int argc, VALUE *argv, VALUE klass)
|
|
210
210
|
|
211
211
|
scanned_args = rb_scan_args(argc, argv, "11", &document, &parse_options);
|
212
212
|
|
213
|
-
|
213
|
+
Noko_Node_Get_Struct(document, xmlDoc, doc);
|
214
214
|
doc = doc->doc; /* In case someone passes us a node. ugh. */
|
215
215
|
|
216
216
|
if (scanned_args == 1) {
|
data/ext/nokogiri/xml_text.c
CHANGED
@@ -20,7 +20,7 @@ new (int argc, VALUE *argv, VALUE klass)
|
|
20
20
|
|
21
21
|
rb_scan_args(argc, argv, "2*", &string, &document, &rest);
|
22
22
|
|
23
|
-
|
23
|
+
Noko_Node_Get_Struct(document, xmlDoc, doc);
|
24
24
|
|
25
25
|
node = xmlNewText((xmlChar *)StringValueCStr(string));
|
26
26
|
node->doc = doc->doc;
|
@@ -28,7 +28,7 @@ module Nokogiri
|
|
28
28
|
###
|
29
29
|
# Parse html stored in +data+ using +encoding+
|
30
30
|
def parse_memory(data, encoding = "UTF-8")
|
31
|
-
raise
|
31
|
+
raise TypeError unless String === data
|
32
32
|
return if data.empty?
|
33
33
|
|
34
34
|
ctx = ParserContext.memory(data, encoding)
|
data/lib/nokogiri/nokogiri.jar
CHANGED
Binary file
|
data/lib/nokogiri/xml/reader.rb
CHANGED
@@ -83,16 +83,14 @@ module Nokogiri
|
|
83
83
|
end
|
84
84
|
private :initialize
|
85
85
|
|
86
|
-
# Get the attributes of the current node as a Hash
|
86
|
+
# Get the attributes and namespaces of the current node as a Hash.
|
87
87
|
#
|
88
|
-
#
|
88
|
+
# This is the union of Reader#attribute_hash and Reader#namespaces
|
89
|
+
#
|
90
|
+
# [Returns]
|
91
|
+
# (Hash<String, String>) Attribute names and values, and namespace prefixes and hrefs.
|
89
92
|
def attributes
|
90
|
-
|
91
|
-
hash[node.name] = node.to_s
|
92
|
-
end
|
93
|
-
ns = namespaces
|
94
|
-
attrs_hash.merge!(ns) if ns
|
95
|
-
attrs_hash
|
93
|
+
attribute_hash.merge(namespaces)
|
96
94
|
end
|
97
95
|
|
98
96
|
###
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nokogiri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.13.
|
4
|
+
version: 1.13.8
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Mike Dalessio
|
@@ -20,7 +20,7 @@ authors:
|
|
20
20
|
autorequire:
|
21
21
|
bindir: bin
|
22
22
|
cert_chain: []
|
23
|
-
date: 2022-
|
23
|
+
date: 2022-07-23 00:00:00.000000000 Z
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,17 +123,17 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Dependency
|
124
124
|
requirement: !ruby/object:Gem::Requirement
|
125
125
|
requirements:
|
126
|
-
- -
|
126
|
+
- - '='
|
127
127
|
- !ruby/object:Gem::Version
|
128
|
-
version:
|
128
|
+
version: 1.2.2
|
129
129
|
name: rake-compiler-dock
|
130
130
|
prerelease: false
|
131
131
|
type: :development
|
132
132
|
version_requirements: !ruby/object:Gem::Requirement
|
133
133
|
requirements:
|
134
|
-
- -
|
134
|
+
- - '='
|
135
135
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
136
|
+
version: 1.2.2
|
137
137
|
- !ruby/object:Gem::Dependency
|
138
138
|
requirement: !ruby/object:Gem::Requirement
|
139
139
|
requirements:
|
@@ -167,10 +167,7 @@ dependencies:
|
|
167
167
|
requirements:
|
168
168
|
- - "~>"
|
169
169
|
- !ruby/object:Gem::Version
|
170
|
-
version:
|
171
|
-
- - ">="
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: 1.28.2
|
170
|
+
version: 1.30.1
|
174
171
|
name: rubocop
|
175
172
|
prerelease: false
|
176
173
|
type: :development
|
@@ -178,10 +175,7 @@ dependencies:
|
|
178
175
|
requirements:
|
179
176
|
- - "~>"
|
180
177
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
182
|
-
- - ">="
|
183
|
-
- !ruby/object:Gem::Version
|
184
|
-
version: 1.28.2
|
178
|
+
version: 1.30.1
|
185
179
|
- !ruby/object:Gem::Dependency
|
186
180
|
requirement: !ruby/object:Gem::Requirement
|
187
181
|
requirements:
|
@@ -227,17 +221,17 @@ dependencies:
|
|
227
221
|
- !ruby/object:Gem::Dependency
|
228
222
|
requirement: !ruby/object:Gem::Requirement
|
229
223
|
requirements:
|
230
|
-
- -
|
224
|
+
- - '='
|
231
225
|
- !ruby/object:Gem::Version
|
232
|
-
version:
|
226
|
+
version: 2.5.0
|
233
227
|
name: rubocop-shopify
|
234
228
|
prerelease: false
|
235
229
|
type: :development
|
236
230
|
version_requirements: !ruby/object:Gem::Requirement
|
237
231
|
requirements:
|
238
|
-
- -
|
232
|
+
- - '='
|
239
233
|
- !ruby/object:Gem::Version
|
240
|
-
version:
|
234
|
+
version: 2.5.0
|
241
235
|
- !ruby/object:Gem::Dependency
|
242
236
|
requirement: !ruby/object:Gem::Requirement
|
243
237
|
requirements:
|