xmlmapper 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/xmlmapper.rb +26 -1
- data/lib/xmlmapper/version.rb +1 -1
- data/spec/to_xml_with_namespaces_spec.rb +31 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2751c0d13928157eb7e417f96fd379e3bb38a20
|
4
|
+
data.tar.gz: 6fcbf0cf9ffb20975b4d01b8d6e84e73eddf58b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9acda69db552cdd80c9ec8adce3149f255ba9d8fc5a0c858e44423c7e3c36e099f21fab71960427dd52bbda8eafa9494a4d30744d56302b0cb5abeeffedf71b
|
7
|
+
data.tar.gz: 8ce8d94c5d2d26e9b0cc4f77ee74250e8cabfa19225ec724b0cb1853d8927181ffda43766c79549ff8f6f19acbb67e3451ecb312ad8154b99878c5bc116f6978
|
data/lib/xmlmapper.rb
CHANGED
@@ -687,7 +687,32 @@ module XmlMapper
|
|
687
687
|
# an empty element will be written to the xml
|
688
688
|
#
|
689
689
|
if value.nil? && element.options[:single] && element.options[:state_when_nil]
|
690
|
-
|
690
|
+
# NOTE In JRuby 9.0.4.0+ and Nokogiri version 1.6.8, Nokogiri::XML::Builder::NodeBuilder
|
691
|
+
# does not retain the XML namespace prefix for an element when adding an element
|
692
|
+
# to a parent node.
|
693
|
+
#
|
694
|
+
# The namespace prefix must be specified when adding the node to its parent.
|
695
|
+
# This issue manifests when setting an element's :state_when_nil' option to true.
|
696
|
+
#
|
697
|
+
# This JRuby workaround is intended for XML element prefixes that originate from a
|
698
|
+
# single namespace defined in 'registered_namespaces'. If there are
|
699
|
+
# multiple namespaces defined in the 'registered_namespaces' array,
|
700
|
+
# then the first namespace is selected.
|
701
|
+
#
|
702
|
+
# Possible related open issues in Nokogiri:
|
703
|
+
# 1. Nokogiri under jruby fails to create namespaces named the same as a sibling
|
704
|
+
# https://github.com/sparklemotion/nokogiri/issues/1247
|
705
|
+
# 2. Attribute loses namespace when node moved
|
706
|
+
# https://github.com/sparklemotion/nokogiri/issues/1278
|
707
|
+
# 3. Adding namespace-less node to namespaced parent attaches the parent namespace to the child
|
708
|
+
# https://github.com/sparklemotion/nokogiri/issues/425
|
709
|
+
#
|
710
|
+
if RUBY_ENGINE == 'jruby' && !registered_namespaces.empty?
|
711
|
+
ns = registered_namespaces.keys.first.to_sym
|
712
|
+
xml[ns].send("#{tag}_","")
|
713
|
+
else
|
714
|
+
xml.send("#{tag}_","")
|
715
|
+
end
|
691
716
|
end
|
692
717
|
|
693
718
|
#
|
data/lib/xmlmapper/version.rb
CHANGED
@@ -138,8 +138,15 @@ describe "Saving #to_xml", "with xml namespaces" do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
context "when an element has a 'state_when_nil' parameter" do
|
141
|
+
let(:element) { subject.xpath('address:description').first }
|
142
|
+
|
141
143
|
it "saves an empty element" do
|
142
|
-
expect(
|
144
|
+
expect(element.text).to eq ""
|
145
|
+
end
|
146
|
+
|
147
|
+
it "the empty element has the correct namespace prefix from the array of registered namespaces" do
|
148
|
+
ns_scopes = element.namespace_scopes
|
149
|
+
expect(ns_scopes.select { |ns| ns == element.namespace }.first.prefix).to eq "address"
|
143
150
|
end
|
144
151
|
end
|
145
152
|
|
@@ -194,10 +201,27 @@ describe "Saving #to_xml", "with xml namespaces" do
|
|
194
201
|
end
|
195
202
|
end
|
196
203
|
|
204
|
+
# NOTE While the original implementation of the test below is correct, the order of XML namespaces
|
205
|
+
# in the XML generated by 'to_xml' differs under JRuby and MRI. In terms of information content,
|
206
|
+
# the XML produced under both platforms are identical. However, the difference in namespace ordering
|
207
|
+
# will produce different XML documents and consequently XML digests. The test below and various tests
|
208
|
+
# in the 'libsaml' gem will compare XML documents and digests of XML documents generated by 'to_xml' which,
|
209
|
+
# while informationally correct, have different values. Unfortunately, the cause of this behavior has
|
210
|
+
# not been identified. In the meantime, it is important to explictly call out this behavior.
|
211
|
+
|
197
212
|
context 'namespace supplied by element declaration trumps namespace ' \
|
198
213
|
'specified by element class' do
|
199
214
|
|
200
|
-
let(:
|
215
|
+
let(:expected_xml_jruby) do
|
216
|
+
<<-XML.gsub(/^\s*\|/, '')
|
217
|
+
|<?xml version="1.0"?>
|
218
|
+
|<coffeemachine xmlns:beverage="http://beverages.org/Beverage/0.1" xmlns:coffee="http://coffee.org/Coffee/0.1">
|
219
|
+
| <beverage:beverage name="coffee"/>
|
220
|
+
|</coffeemachine>
|
221
|
+
XML
|
222
|
+
end
|
223
|
+
|
224
|
+
let(:expected_xml_mri) do
|
201
225
|
<<-XML.gsub(/^\s*\|/, '')
|
202
226
|
|<?xml version="1.0"?>
|
203
227
|
|<coffeemachine xmlns:coffee="http://coffee.org/Coffee/0.1" xmlns:beverage="http://beverages.org/Beverage/0.1">
|
@@ -224,7 +248,11 @@ describe "Saving #to_xml", "with xml namespaces" do
|
|
224
248
|
it 'uses the element declaration namespace on the element' do
|
225
249
|
machine = CoffeeMachine.new
|
226
250
|
machine.beverage = Beverage.new.tap {|obj| obj.name = 'coffee'}
|
227
|
-
|
251
|
+
if RUBY_ENGINE == 'jruby'
|
252
|
+
machine.to_xml.should be == expected_xml_jruby
|
253
|
+
else
|
254
|
+
machine.to_xml.should be == expected_xml_mri
|
255
|
+
end
|
228
256
|
end
|
229
257
|
end
|
230
258
|
|