nokogiri 1.12.3 → 1.12.4
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/xml_node.c +7 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/xml/builder.rb +38 -0
- data/lib/nokogiri/xml/document.rb +46 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f486e94da9d2891b2816c34853ef6d0cec2f13f71685b41038b2b27129477667
|
4
|
+
data.tar.gz: ebca30b8d695fcf0a769612f765195d301f0791eef181ebd2a3c0b64135b7a72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fb58443592320180c6552c681ce2d62fea5b0c0b92dab564256c9ba8380694c2b62b292312afd844cb185a1b63088937336492d379b1a580e4438748d469bd1
|
7
|
+
data.tar.gz: 03af04e9373e74d89d2568f58e1c94f088b675be22c73f4f02babe38e1a6671dc5a1a01c3400c3d92c4574dfa30f84ec13fbc41c6e1ad80924b5bfaf8a93dc1e
|
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;
|
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
|
##
|
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.4
|
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-08-
|
23
|
+
date: 2021-08-29 00:00:00.000000000 Z
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: racc
|