nokogiri 1.12.3-java → 1.12.4-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c02e2a1054020fd7f9535b42d8995c8342b1c762f4bd4688aa3d00fb01975af4
4
- data.tar.gz: 351851882dbb2fc7648bef467aa58a4638fec8a8a40b5daf79763198cfa05c01
3
+ metadata.gz: 7622742928c0922dc547c7dae9e890589b08828654bbead397c7970ceb084c78
4
+ data.tar.gz: 903b5117d4674e82ccb44a767ff11d4abcb04015cecdecceebc334e3bd8c49be
5
5
  SHA512:
6
- metadata.gz: 35dd3c4b2162e22069937b33d72a845649c0bb270767092532fd35194b5c06afe2da284ee895e5c114a7d04acff9b9b2c6c19c5599db691667f0adbee2c4f102
7
- data.tar.gz: f8120c65a723d884e58ea1dd88feb725584a3843d278c8875ce80eb7e004b0837d5c382150352f4fa8476ae6b1ae35a15f640d8c62ddfe7a8e98702d286d460b
6
+ metadata.gz: cacd709443f6da7d40dc5fe4810345e63ede7ff37f5a36196c2b934523cb8eb589eec07c07ac5c542e7047f1ec0a9804ad265e490759d58f4506d086a490ca9f
7
+ data.tar.gz: 9457959a40c7e1474a75fd618a25029c407ef88b32a77a9521f7665184f61c835859c201ce664c82c38b39185ef9dc682d991cdc0ae648fbbfbb9bca138815e9
@@ -34,8 +34,6 @@ import org.w3c.dom.NamedNodeMap;
34
34
  public class XmlDocumentFragment extends XmlNode
35
35
  {
36
36
 
37
- private XmlElement fragmentContext;
38
-
39
37
  public
40
38
  XmlDocumentFragment(Ruby ruby)
41
39
  {
@@ -75,10 +73,6 @@ public class XmlDocumentFragment extends XmlNode
75
73
  fragment.setDocument(context, doc);
76
74
  fragment.setNode(context.runtime, doc.getDocument().createDocumentFragment());
77
75
 
78
- //TODO: Get namespace definitions from doc.
79
- if (args.length == 3 && args[2] != null && args[2] instanceof XmlElement) {
80
- fragment.fragmentContext = (XmlElement)args[2];
81
- }
82
76
  Helpers.invoke(context, fragment, "initialize", args);
83
77
  return fragment;
84
78
  }
@@ -158,12 +152,6 @@ public class XmlDocumentFragment extends XmlNode
158
152
  return null;
159
153
  }
160
154
 
161
- public XmlElement
162
- getFragmentContext()
163
- {
164
- return fragmentContext;
165
- }
166
-
167
155
  @Override
168
156
  public void
169
157
  relink_namespace(ThreadContext context)
@@ -12,6 +12,7 @@ import java.util.*;
12
12
  import org.apache.xerces.dom.CoreDocumentImpl;
13
13
  import org.jruby.Ruby;
14
14
  import org.jruby.RubyArray;
15
+ import org.jruby.RubyBoolean;
15
16
  import org.jruby.RubyClass;
16
17
  import org.jruby.RubyFixnum;
17
18
  import org.jruby.RubyInteger;
@@ -421,7 +422,14 @@ public class XmlNode extends RubyObject
421
422
  String nsURI = e.lookupNamespaceURI(prefix);
422
423
  this.node = NokogiriHelpers.renameNode(e, nsURI, e.getNodeName());
423
424
 
424
- if (nsURI == null || nsURI.isEmpty()) { return; }
425
+ if (nsURI == null || nsURI.isEmpty()) {
426
+ RubyBoolean ns_inherit =
427
+ (RubyBoolean)document(context.runtime).getInstanceVariable("@namespace_inheritance");
428
+ if (ns_inherit.isTrue()) {
429
+ set_namespace(context, ((XmlNode)parent(context)).namespace(context));
430
+ }
431
+ return;
432
+ }
425
433
 
426
434
  String currentPrefix = e.getParentNode().lookupPrefix(nsURI);
427
435
  String currentURI = e.getParentNode().lookupNamespaceURI(prefix);
@@ -1743,24 +1751,11 @@ public class XmlNode extends RubyObject
1743
1751
  e.appendChild(otherNode);
1744
1752
  otherNode = e;
1745
1753
  } else {
1746
- addNamespaceURIIfNeeded(otherNode);
1747
1754
  parent.appendChild(otherNode);
1748
1755
  }
1749
1756
  return new Node[] { otherNode };
1750
1757
  }
1751
1758
 
1752
- private void
1753
- addNamespaceURIIfNeeded(Node child)
1754
- {
1755
- if (this instanceof XmlDocumentFragment && ((XmlDocumentFragment) this).getFragmentContext() != null) {
1756
- XmlElement fragmentContext = ((XmlDocumentFragment) this).getFragmentContext();
1757
- String namespace_uri = fragmentContext.node.getNamespaceURI();
1758
- if (namespace_uri != null && namespace_uri.length() > 0) {
1759
- NokogiriHelpers.renameNode(child, namespace_uri, child.getNodeName());
1760
- }
1761
- }
1762
- }
1763
-
1764
1759
  protected void
1765
1760
  adoptAsPrevSibling(ThreadContext context,
1766
1761
  Node parent,
@@ -276,7 +276,7 @@ public class XmlSchema extends RubyObject
276
276
  String systemId,
277
277
  String baseURI)
278
278
  {
279
- if (noNet && (systemId.startsWith("http://") || systemId.startsWith("ftp://"))) {
279
+ if (noNet && systemId != null && (systemId.startsWith("http://") || systemId.startsWith("ftp://"))) {
280
280
  if (systemId.startsWith(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
281
281
  return null; // use default resolver
282
282
  }
@@ -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;
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Nokogiri
3
3
  # The version of Nokogiri you are using
4
- VERSION = "1.12.3"
4
+ VERSION = "1.12.4"
5
5
  end
@@ -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.3
4
+ version: 1.12.4
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: 2021-08-10 00:00:00.000000000 Z
23
+ date: 2021-08-29 00:00:00.000000000 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  requirement: !ruby/object:Gem::Requirement