xmlmapper 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb50a11700e4020d9084eda1c4cf15a4aafe660a
4
- data.tar.gz: 97d7d192b1588615f37fe137cac1bbc80af791da
3
+ metadata.gz: b2751c0d13928157eb7e417f96fd379e3bb38a20
4
+ data.tar.gz: 6fcbf0cf9ffb20975b4d01b8d6e84e73eddf58b1
5
5
  SHA512:
6
- metadata.gz: d8a935ac03e952b23034bf5dde9069aad8752f9d85fcb782abe5d194b05535584dd508493c69c6d8edd7c3e989b4d9f2c318765210bb886f4dcbfda0153731cf
7
- data.tar.gz: 49ff18e349ddca6aff4ec59aa9848ee6777bb4e192a249b18a12458e3373c6ffef00a418eca277b3ee4882603f20ad91747c577e9ae47fe16e5a511c76c08f54
6
+ metadata.gz: f9acda69db552cdd80c9ec8adce3149f255ba9d8fc5a0c858e44423c7e3c36e099f21fab71960427dd52bbda8eafa9494a4d30744d56302b0cb5abeeffedf71b
7
+ data.tar.gz: 8ce8d94c5d2d26e9b0cc4f77ee74250e8cabfa19225ec724b0cb1853d8927181ffda43766c79549ff8f6f19acbb67e3451ecb312ad8154b99878c5bc116f6978
@@ -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
- xml.send("#{tag}_","")
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
  #
@@ -1,3 +1,3 @@
1
1
  module XmlMapper
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -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(subject.xpath('address:description').text).to eq ""
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(:expected_xml) do
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
- machine.to_xml.should be == expected_xml
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlmapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Le Berrigaud