nokogiri 1.12.1 → 1.12.5
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/nokogiri/extconf.rb +4 -0
- data/ext/nokogiri/gumbo.c +11 -11
- data/ext/nokogiri/html4_element_description.c +1 -1
- data/ext/nokogiri/html4_sax_parser_context.c +2 -1
- data/ext/nokogiri/nokogiri.c +1 -1
- data/ext/nokogiri/nokogiri.h +3 -0
- data/ext/nokogiri/xml_document.c +1 -1
- data/ext/nokogiri/xml_namespace.c +2 -2
- data/ext/nokogiri/xml_node.c +9 -2
- data/lib/nokogiri/extension.rb +6 -1
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/xml/builder.rb +38 -0
- data/lib/nokogiri/xml/document.rb +46 -0
- data/lib/nokogiri/xml/node/save_options.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23ffbd6c1e4af09a26b9e6c9f4ecd6afda89115f024bf80e6b908b31e4d03e71
|
4
|
+
data.tar.gz: 7dd0bd80a3a48a11e581677e93e4645629260d82b05311d8d62da8185a417e1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e54c3269141d29fa515d2bac02d5c02e2a2d54feb0e336b4d94d4bc32618653812fe308bacb55983293886903baffb14d4eb70032ed6b9b8482bba4530aeb78f
|
7
|
+
data.tar.gz: 5d76ebeffb4c1180c03eaf946ee5a2d13d80cc942aba1cae0b04f11a359b5adc5508fe8cbeb58c89cf4cc1d6232f6c6afad38264102282a314693e83fd05426d
|
data/ext/nokogiri/extconf.rb
CHANGED
@@ -594,6 +594,10 @@ append_cppflags(ENV["CPPFLAGS"].split) unless ENV["CPPFLAGS"].nil?
|
|
594
594
|
append_ldflags(ENV["LDFLAGS"].split) unless ENV["LDFLAGS"].nil?
|
595
595
|
$LIBS = concat_flags($LIBS, ENV["LIBS"])
|
596
596
|
|
597
|
+
# nokogumbo code uses C90/C99 features, let's make sure older compilers won't give
|
598
|
+
# errors/warnings. see #2302
|
599
|
+
append_cflags(["-std=c99", "-Wno-declaration-after-statement"])
|
600
|
+
|
597
601
|
# always include debugging information
|
598
602
|
append_cflags("-g")
|
599
603
|
|
data/ext/nokogiri/gumbo.c
CHANGED
@@ -75,7 +75,7 @@ new_html_doc(const char *dtd_name, const char *system, const char *public)
|
|
75
75
|
htmlDocPtr doc = htmlNewDocNoDtD(/* URI */ NULL, /* ExternalID */NULL);
|
76
76
|
assert(doc);
|
77
77
|
if (dtd_name) {
|
78
|
-
xmlCreateIntSubset(doc,
|
78
|
+
xmlCreateIntSubset(doc, (const xmlChar *)dtd_name, (const xmlChar *)public, (const xmlChar *)system);
|
79
79
|
}
|
80
80
|
return doc;
|
81
81
|
}
|
@@ -120,11 +120,11 @@ lookup_or_add_ns(
|
|
120
120
|
const char *prefix
|
121
121
|
)
|
122
122
|
{
|
123
|
-
xmlNsPtr ns = xmlSearchNs(doc, root,
|
123
|
+
xmlNsPtr ns = xmlSearchNs(doc, root, (const xmlChar *)prefix);
|
124
124
|
if (ns) {
|
125
125
|
return ns;
|
126
126
|
}
|
127
|
-
return xmlNewNs(root,
|
127
|
+
return xmlNewNs(root, (const xmlChar *)href, (const xmlChar *)prefix);
|
128
128
|
}
|
129
129
|
|
130
130
|
static void
|
@@ -181,20 +181,20 @@ build_tree(
|
|
181
181
|
|
182
182
|
case GUMBO_NODE_TEXT:
|
183
183
|
case GUMBO_NODE_WHITESPACE:
|
184
|
-
xml_child = xmlNewDocText(doc,
|
184
|
+
xml_child = xmlNewDocText(doc, (const xmlChar *)gumbo_child->v.text.text);
|
185
185
|
set_line(xml_child, gumbo_child->v.text.start_pos.line);
|
186
186
|
xmlAddChild(xml_node, xml_child);
|
187
187
|
break;
|
188
188
|
|
189
189
|
case GUMBO_NODE_CDATA:
|
190
|
-
xml_child = xmlNewCDataBlock(doc,
|
190
|
+
xml_child = xmlNewCDataBlock(doc, (const xmlChar *)gumbo_child->v.text.text,
|
191
191
|
(int) strlen(gumbo_child->v.text.text));
|
192
192
|
set_line(xml_child, gumbo_child->v.text.start_pos.line);
|
193
193
|
xmlAddChild(xml_node, xml_child);
|
194
194
|
break;
|
195
195
|
|
196
196
|
case GUMBO_NODE_COMMENT:
|
197
|
-
xml_child = xmlNewDocComment(doc,
|
197
|
+
xml_child = xmlNewDocComment(doc, (const xmlChar *)gumbo_child->v.text.text);
|
198
198
|
set_line(xml_child, gumbo_child->v.text.start_pos.line);
|
199
199
|
xmlAddChild(xml_node, xml_child);
|
200
200
|
break;
|
@@ -202,7 +202,7 @@ build_tree(
|
|
202
202
|
case GUMBO_NODE_TEMPLATE:
|
203
203
|
// XXX: Should create a template element and a new DocumentFragment
|
204
204
|
case GUMBO_NODE_ELEMENT: {
|
205
|
-
xml_child = xmlNewDocNode(doc, NULL,
|
205
|
+
xml_child = xmlNewDocNode(doc, NULL, (const xmlChar *)gumbo_child->v.element.name, NULL);
|
206
206
|
set_line(xml_child, gumbo_child->v.element.start_pos.line);
|
207
207
|
if (xml_root == NULL) {
|
208
208
|
xml_root = xml_child;
|
@@ -244,7 +244,7 @@ build_tree(
|
|
244
244
|
default:
|
245
245
|
ns = NULL;
|
246
246
|
}
|
247
|
-
xmlNewNsProp(xml_child, ns,
|
247
|
+
xmlNewNsProp(xml_child, ns, (const xmlChar *)attr->name, (const xmlChar *)attr->value);
|
248
248
|
}
|
249
249
|
|
250
250
|
// Add children for this element.
|
@@ -303,7 +303,7 @@ typedef struct {
|
|
303
303
|
static VALUE
|
304
304
|
parse_cleanup(VALUE parse_args)
|
305
305
|
{
|
306
|
-
ParseArgs *args = (ParseArgs*)parse_args;
|
306
|
+
ParseArgs *args = (ParseArgs *)parse_args;
|
307
307
|
gumbo_destroy_output(args->output);
|
308
308
|
// Make sure garbage collection doesn't mark the objects as being live based
|
309
309
|
// on references from the ParseArgs. This may be unnecessary.
|
@@ -342,7 +342,7 @@ parse(VALUE self, VALUE input, VALUE url, VALUE max_attributes, VALUE max_errors
|
|
342
342
|
static VALUE
|
343
343
|
parse_continue(VALUE parse_args)
|
344
344
|
{
|
345
|
-
ParseArgs *args = (ParseArgs*)parse_args;
|
345
|
+
ParseArgs *args = (ParseArgs *)parse_args;
|
346
346
|
GumboOutput *output = args->output;
|
347
347
|
xmlDocPtr doc;
|
348
348
|
if (output->document->v.document.has_doctype) {
|
@@ -552,7 +552,7 @@ error:
|
|
552
552
|
static VALUE
|
553
553
|
fragment_continue(VALUE parse_args)
|
554
554
|
{
|
555
|
-
ParseArgs *args = (ParseArgs*)parse_args;
|
555
|
+
ParseArgs *args = (ParseArgs *)parse_args;
|
556
556
|
GumboOutput *output = args->output;
|
557
557
|
VALUE doc_fragment = args->url_or_frag;
|
558
558
|
xmlDocPtr xml_doc = args->doc;
|
@@ -266,7 +266,7 @@ get_description(VALUE klass, VALUE tag_name)
|
|
266
266
|
);
|
267
267
|
|
268
268
|
if (NULL == description) { return Qnil; }
|
269
|
-
return Data_Wrap_Struct(klass, 0, 0, (void
|
269
|
+
return Data_Wrap_Struct(klass, 0, 0, DISCARD_CONST_QUAL(void *, description));
|
270
270
|
}
|
271
271
|
|
272
272
|
void
|
@@ -110,7 +110,8 @@ void
|
|
110
110
|
noko_init_html_sax_parser_context()
|
111
111
|
{
|
112
112
|
assert(cNokogiriXmlSaxParserContext);
|
113
|
-
cNokogiriHtml4SaxParserContext = rb_define_class_under(mNokogiriHtml4Sax, "ParserContext",
|
113
|
+
cNokogiriHtml4SaxParserContext = rb_define_class_under(mNokogiriHtml4Sax, "ParserContext",
|
114
|
+
cNokogiriXmlSaxParserContext);
|
114
115
|
|
115
116
|
rb_define_singleton_method(cNokogiriHtml4SaxParserContext, "memory", parse_memory, 2);
|
116
117
|
rb_define_singleton_method(cNokogiriHtml4SaxParserContext, "file", parse_file, 2);
|
data/ext/nokogiri/nokogiri.c
CHANGED
@@ -220,7 +220,7 @@ Init_nokogiri()
|
|
220
220
|
xmlInitParser();
|
221
221
|
exsltRegisterAll();
|
222
222
|
|
223
|
-
if (xsltExtModuleFunctionLookup((xmlChar*)"date-time", EXSLT_DATE_NAMESPACE)) {
|
223
|
+
if (xsltExtModuleFunctionLookup((const xmlChar *)"date-time", EXSLT_DATE_NAMESPACE)) {
|
224
224
|
rb_const_set(mNokogiri, rb_intern("LIBXSLT_DATETIME_ENABLED"), Qtrue);
|
225
225
|
} else {
|
226
226
|
rb_const_set(mNokogiri, rb_intern("LIBXSLT_DATETIME_ENABLED"), Qfalse);
|
data/ext/nokogiri/nokogiri.h
CHANGED
@@ -197,6 +197,9 @@ NOKOPUBFUN VALUE Nokogiri_wrap_xml_document(VALUE klass,
|
|
197
197
|
#define NOKOGIRI_SAX_TUPLE_NEW(_ctxt, _self) nokogiri_sax_tuple_new(_ctxt, _self)
|
198
198
|
#define NOKOGIRI_SAX_TUPLE_DESTROY(_tuple) free(_tuple)
|
199
199
|
|
200
|
+
#define DISCARD_CONST_QUAL(t, v) ((t)(uintptr_t)(v))
|
201
|
+
#define DISCARD_CONST_QUAL_XMLCHAR(v) DISCARD_CONST_QUAL(xmlChar *, v)
|
202
|
+
|
200
203
|
void Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state);
|
201
204
|
void Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state, void *user_data,
|
202
205
|
xmlStructuredErrorFunc handler);
|
data/ext/nokogiri/xml_document.c
CHANGED
@@ -213,7 +213,7 @@ set_encoding(VALUE self, VALUE encoding)
|
|
213
213
|
Data_Get_Struct(self, xmlDoc, doc);
|
214
214
|
|
215
215
|
if (doc->encoding) {
|
216
|
-
|
216
|
+
xmlFree(DISCARD_CONST_QUAL_XMLCHAR(doc->encoding));
|
217
217
|
}
|
218
218
|
|
219
219
|
doc->encoding = xmlStrdup((xmlChar *)StringValueCStr(encoding));
|
@@ -33,10 +33,10 @@ dealloc_namespace(xmlNsPtr ns)
|
|
33
33
|
*/
|
34
34
|
NOKOGIRI_DEBUG_START(ns) ;
|
35
35
|
if (ns->href) {
|
36
|
-
xmlFree((
|
36
|
+
xmlFree(DISCARD_CONST_QUAL_XMLCHAR(ns->href));
|
37
37
|
}
|
38
38
|
if (ns->prefix) {
|
39
|
-
xmlFree((
|
39
|
+
xmlFree(DISCARD_CONST_QUAL_XMLCHAR(ns->prefix));
|
40
40
|
}
|
41
41
|
xmlFree(ns);
|
42
42
|
NOKOGIRI_DEBUG_END(ns) ;
|
data/ext/nokogiri/xml_node.c
CHANGED
@@ -69,6 +69,13 @@ relink_namespace(xmlNodePtr reparented)
|
|
69
69
|
/* Avoid segv when relinking against unlinked nodes. */
|
70
70
|
if (reparented->type != XML_ELEMENT_NODE || !reparented->parent) { return; }
|
71
71
|
|
72
|
+
/* Make sure that our reparented node has the correct namespaces */
|
73
|
+
if (!reparented->ns &&
|
74
|
+
(reparented->doc != (xmlDocPtr)reparented->parent) &&
|
75
|
+
(rb_iv_get(DOC_RUBY_OBJECT(reparented->doc), "@namespace_inheritance") == Qtrue)) {
|
76
|
+
xmlSetNs(reparented, reparented->parent->ns);
|
77
|
+
}
|
78
|
+
|
72
79
|
/* Search our parents for an existing definition */
|
73
80
|
if (reparented->nsDef) {
|
74
81
|
xmlNsPtr curr = reparented->nsDef;
|
@@ -304,7 +311,7 @@ ok:
|
|
304
311
|
* issue #391, where new node's prefix may become the string "default"
|
305
312
|
* see libxml2 tree.c xmlNewReconciliedNs which implements this behavior.
|
306
313
|
*/
|
307
|
-
xmlFree((
|
314
|
+
xmlFree(DISCARD_CONST_QUAL_XMLCHAR(reparentee->ns->prefix));
|
308
315
|
reparentee->ns->prefix = NULL;
|
309
316
|
}
|
310
317
|
}
|
@@ -934,7 +941,7 @@ get(VALUE self, VALUE rattribute)
|
|
934
941
|
Data_Get_Struct(self, xmlNode, node);
|
935
942
|
attribute = xmlCharStrdup(StringValueCStr(rattribute));
|
936
943
|
|
937
|
-
colon = (
|
944
|
+
colon = DISCARD_CONST_QUAL_XMLCHAR(xmlStrchr(attribute, (const xmlChar)':'));
|
938
945
|
if (colon) {
|
939
946
|
/* split the attribute string into separate prefix and name by
|
940
947
|
* null-terminating the prefix at the colon */
|
data/lib/nokogiri/extension.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# load the C or Java extension
|
4
4
|
begin
|
5
|
+
# native precompiled gems package shared libraries in <gem_dir>/lib/nokogiri/<ruby_version>
|
5
6
|
::RUBY_VERSION =~ /(\d+\.\d+)/
|
6
7
|
require_relative "#{Regexp.last_match(1)}/nokogiri"
|
7
8
|
rescue LoadError => e
|
@@ -22,5 +23,9 @@ rescue LoadError => e
|
|
22
23
|
EOM
|
23
24
|
raise e
|
24
25
|
end
|
25
|
-
|
26
|
+
|
27
|
+
# use "require" instead of "require_relative" because non-native gems will place C extension files
|
28
|
+
# in Gem::BasicSpecification#extension_dir after compilation (during normal installation), which
|
29
|
+
# is in $LOAD_PATH but not necessarily relative to this file (see #2300)
|
30
|
+
require "nokogiri/nokogiri"
|
26
31
|
end
|
data/lib/nokogiri/xml/builder.rb
CHANGED
@@ -196,6 +196,41 @@ module Nokogiri
|
|
196
196
|
#
|
197
197
|
# Note the "foo:object" tag.
|
198
198
|
#
|
199
|
+
# === Namespace inheritance
|
200
|
+
#
|
201
|
+
# In the Builder context, children will inherit their parent's namespace. This is the same
|
202
|
+
# behavior as if the underlying {XML::Document} set +namespace_inheritance+ to +true+:
|
203
|
+
#
|
204
|
+
# result = Nokogiri::XML::Builder.new do |xml|
|
205
|
+
# xml["soapenv"].Envelope("xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/") do
|
206
|
+
# xml.Header
|
207
|
+
# end
|
208
|
+
# end
|
209
|
+
# result.doc.to_xml
|
210
|
+
# # => <?xml version="1.0" encoding="utf-8"?>
|
211
|
+
# # <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
|
212
|
+
# # <soapenv:Header/>
|
213
|
+
# # </soapenv:Envelope>
|
214
|
+
#
|
215
|
+
# Users may turn this behavior off by passing a keyword argument +namespace_inheritance:false+
|
216
|
+
# to the initializer:
|
217
|
+
#
|
218
|
+
# result = Nokogiri::XML::Builder.new(namespace_inheritance: false) do |xml|
|
219
|
+
# xml["soapenv"].Envelope("xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/") do
|
220
|
+
# xml.Header
|
221
|
+
# xml["soapenv"].Body # users may explicitly opt into the namespace
|
222
|
+
# end
|
223
|
+
# end
|
224
|
+
# result.doc.to_xml
|
225
|
+
# # => <?xml version="1.0" encoding="utf-8"?>
|
226
|
+
# # <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
|
227
|
+
# # <Header/>
|
228
|
+
# # <soapenv:Body/>
|
229
|
+
# # </soapenv:Envelope>
|
230
|
+
#
|
231
|
+
# For more information on namespace inheritance, please see {XML::Document#namespace_inheritance}
|
232
|
+
#
|
233
|
+
#
|
199
234
|
# == Document Types
|
200
235
|
#
|
201
236
|
# To create a document type (DTD), access use the Builder#doc method to get
|
@@ -226,6 +261,8 @@ module Nokogiri
|
|
226
261
|
# </root>
|
227
262
|
#
|
228
263
|
class Builder
|
264
|
+
DEFAULT_DOCUMENT_OPTIONS = {namespace_inheritance: true}
|
265
|
+
|
229
266
|
# The current Document object being built
|
230
267
|
attr_accessor :doc
|
231
268
|
|
@@ -282,6 +319,7 @@ module Nokogiri
|
|
282
319
|
@arity = nil
|
283
320
|
@ns = nil
|
284
321
|
|
322
|
+
options = DEFAULT_DOCUMENT_OPTIONS.merge(options)
|
285
323
|
options.each do |k, v|
|
286
324
|
@doc.send(:"#{k}=", v)
|
287
325
|
end
|
@@ -113,9 +113,55 @@ module Nokogiri
|
|
113
113
|
# A list of Nokogiri::XML::SyntaxError found when parsing a document
|
114
114
|
attr_accessor :errors
|
115
115
|
|
116
|
+
# When true, reparented elements without a namespace will inherit their new parent's
|
117
|
+
# namespace (if one exists). Defaults to +false+.
|
118
|
+
#
|
119
|
+
# @example Default behavior of namespace inheritance
|
120
|
+
# xml = <<~EOF
|
121
|
+
# <root xmlns:foo="http://nokogiri.org/default_ns/test/foo">
|
122
|
+
# <foo:parent>
|
123
|
+
# </foo:parent>
|
124
|
+
# </root>
|
125
|
+
# EOF
|
126
|
+
# doc = Nokogiri::XML(xml)
|
127
|
+
# parent = doc.at_xpath("//foo:parent", "foo" => "http://nokogiri.org/default_ns/test/foo")
|
128
|
+
# parent.add_child("<child></child>")
|
129
|
+
# doc.to_xml
|
130
|
+
# # => <?xml version="1.0"?>
|
131
|
+
# # <root xmlns:foo="http://nokogiri.org/default_ns/test/foo">
|
132
|
+
# # <foo:parent>
|
133
|
+
# # <child/>
|
134
|
+
# # </foo:parent>
|
135
|
+
# # </root>
|
136
|
+
#
|
137
|
+
# @example Setting namespace inheritance to +true+
|
138
|
+
# xml = <<~EOF
|
139
|
+
# <root xmlns:foo="http://nokogiri.org/default_ns/test/foo">
|
140
|
+
# <foo:parent>
|
141
|
+
# </foo:parent>
|
142
|
+
# </root>
|
143
|
+
# EOF
|
144
|
+
# doc = Nokogiri::XML(xml)
|
145
|
+
# doc.namespace_inheritance = true
|
146
|
+
# parent = doc.at_xpath("//foo:parent", "foo" => "http://nokogiri.org/default_ns/test/foo")
|
147
|
+
# parent.add_child("<child></child>")
|
148
|
+
# doc.to_xml
|
149
|
+
# # => <?xml version="1.0"?>
|
150
|
+
# # <root xmlns:foo="http://nokogiri.org/default_ns/test/foo">
|
151
|
+
# # <foo:parent>
|
152
|
+
# # <foo:child/>
|
153
|
+
# # </foo:parent>
|
154
|
+
# # </root>
|
155
|
+
#
|
156
|
+
# @return [Boolean]
|
157
|
+
#
|
158
|
+
# @since v1.12.4
|
159
|
+
attr_accessor :namespace_inheritance
|
160
|
+
|
116
161
|
def initialize *args # :nodoc:
|
117
162
|
@errors = []
|
118
163
|
@decorators = nil
|
164
|
+
@namespace_inheritance = false
|
119
165
|
end
|
120
166
|
|
121
167
|
##
|
@@ -34,7 +34,7 @@ module Nokogiri
|
|
34
34
|
DEFAULT_HTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
|
35
35
|
end
|
36
36
|
# the default for XHTML document
|
37
|
-
DEFAULT_XHTML = FORMAT | NO_DECLARATION |
|
37
|
+
DEFAULT_XHTML = FORMAT | NO_DECLARATION | AS_XHTML
|
38
38
|
|
39
39
|
# Integer representation of the SaveOptions
|
40
40
|
attr_reader :options
|
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.12.
|
4
|
+
version: 1.12.5
|
5
5
|
platform: ruby
|
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: 2021-
|
23
|
+
date: 2021-09-27 00:00:00.000000000 Z
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: racc
|
@@ -450,7 +450,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
450
450
|
- !ruby/object:Gem::Version
|
451
451
|
version: '0'
|
452
452
|
requirements: []
|
453
|
-
rubygems_version: 3.2.
|
453
|
+
rubygems_version: 3.2.22
|
454
454
|
signing_key:
|
455
455
|
specification_version: 4
|
456
456
|
summary: Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby.
|