xmlmapper 0.7.1 → 0.8.1

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
- SHA1:
3
- metadata.gz: cb50a11700e4020d9084eda1c4cf15a4aafe660a
4
- data.tar.gz: 97d7d192b1588615f37fe137cac1bbc80af791da
2
+ SHA256:
3
+ metadata.gz: cb7a9048f9c5776bd95d515a304c9eb10874458681f2e271fc0e9be7ee2779d7
4
+ data.tar.gz: e529bfda1112b716a8941d0a43437c5178451473219e3a407aee9c3fbb1a1f1a
5
5
  SHA512:
6
- metadata.gz: d8a935ac03e952b23034bf5dde9069aad8752f9d85fcb782abe5d194b05535584dd508493c69c6d8edd7c3e989b4d9f2c318765210bb886f4dcbfda0153731cf
7
- data.tar.gz: 49ff18e349ddca6aff4ec59aa9848ee6777bb4e192a249b18a12458e3373c6ffef00a418eca277b3ee4882603f20ad91747c577e9ae47fe16e5a511c76c08f54
6
+ metadata.gz: 490ea2b98896969d34d5a8f91fb8dbc254b46d8d2d36cd740eabdf0dececfd986307ed615df7bbede06f570cb5ca43472e0305bdfc53d692f26f80405dcfd267
7
+ data.tar.gz: f77dc1661532920e0f8db940ccb22d6b2ed268987a12ad01bb3293691127212399481f21db2dbe72851103e39b07752ba03fbf08b58d4c872efb4b18a6ce8564
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 0.8.1 / 2021-08-13
2
+
3
+ * Version 0.8.0 fixed a bug with newer versions of nokogiri, however due to the way this fix works it breaks compatability with
4
+ older versions so we now added `'nokogiri', '~> 1.11'` as dependency
5
+ * Update gemspec
6
+
7
+ ## 0.8.0 / 2021-08-12
8
+
9
+ ### WARNING: COMPATABILITY (see 0.8.1)
10
+ * [Fix](https://github.com/digidentity/xmlmapper/pull/2) missing namespace when adding a child
11
+
1
12
  ## 0.7.0
2
13
 
3
14
  * Set xml_value with a non canonicalized version
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- Xmlmapper
1
+ XmlMapper
2
2
  ===========
3
3
 
4
- Xmlmapper allows you to parse XML data and convert it quickly and easily into ruby data structures.
4
+ XmlMapper allows you to parse XML data and convert it quickly and easily into ruby data structures.
5
5
 
6
6
  This project is a fork of the great work done first by
7
7
  [jnunemaker](https://github.com/jnunemaker/happymapper).
data/lib/xmlmapper.rb CHANGED
@@ -687,7 +687,34 @@ 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
+ #
691
+ # NOTE
692
+ # In JRuby 9.0.4.0+ and Nokogiri version 1.6.8 or with Nokogiri version >= 1.12.0 (libxml >= 2.9.12),
693
+ # the Nokogiri::XML::Builder::NodeBuilder does not retain the XML namespace prefix for an element
694
+ # when adding an element to a parent node.
695
+ #
696
+ # The namespace prefix must be specified when adding the node to its parent.
697
+ # This issue manifests when setting an element's :state_when_nil' option to true.
698
+ #
699
+ # This workaround is intended for XML element prefixes that originate from a
700
+ # single namespace defined in 'registered_namespaces'. If there are
701
+ # multiple namespaces defined in the 'registered_namespaces' array,
702
+ # then the first namespace is selected.
703
+ #
704
+ # Possible related open issues in Nokogiri:
705
+ # 1. Nokogiri under jruby fails to create namespaces named the same as a sibling
706
+ # https://github.com/sparklemotion/nokogiri/issues/1247
707
+ # 2. Attribute loses namespace when node moved
708
+ # https://github.com/sparklemotion/nokogiri/issues/1278
709
+ # 3. Adding namespace-less node to namespaced parent attaches the parent namespace to the child
710
+ # https://github.com/sparklemotion/nokogiri/issues/425
711
+ #
712
+ if (RUBY_ENGINE == 'jruby' || Nokogiri.uses_libxml?('>= 2.9.12')) && !registered_namespaces.empty?
713
+ ns = registered_namespaces.keys.first.to_sym
714
+ xml[ns].send("#{tag}_","")
715
+ else
716
+ xml.send("#{tag}_","")
717
+ end
691
718
  end
692
719
 
693
720
  #
@@ -2,7 +2,11 @@ module XmlMapper
2
2
  class TextNode < Item
3
3
 
4
4
  def find(node, namespace, xpath_options)
5
- yield(node.children.detect{|c| c.text?})
5
+ if node.children.any? {|c| c.text?}
6
+ yield(node)
7
+ else
8
+ yield(nil)
9
+ end
6
10
  end
7
11
  end
8
12
  end
@@ -1,3 +1,3 @@
1
1
  module XmlMapper
2
- VERSION = "0.7.1"
2
+ VERSION = '0.8.1'.freeze
3
3
  end
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <textnode>With <!----> Comment</textnode>
@@ -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
 
@@ -554,7 +554,6 @@ end
554
554
  class DefaultNamespaceCombi
555
555
  include XmlMapper
556
556
 
557
-
558
557
  register_namespace 'bk', "urn:loc.gov:books"
559
558
  register_namespace 'isbn', "urn:ISBN:0-395-36341-6"
560
559
  register_namespace 'p', "urn:loc.gov:people"
@@ -567,6 +566,14 @@ class DefaultNamespaceCombi
567
566
  element :author, String, :namespace => 'p', :tag => "author"
568
567
  end
569
568
 
569
+ class TextNodeWithComment
570
+ include XmlMapper
571
+
572
+ tag 'textnode'
573
+
574
+ content :value, String
575
+ end
576
+
570
577
  describe XmlMapper do
571
578
 
572
579
  describe "being included into another class" do
@@ -1134,4 +1141,13 @@ describe XmlMapper do
1134
1141
  end
1135
1142
  end
1136
1143
 
1144
+ context 'text_node with comments' do
1145
+ it 'returns the full text in the node' do
1146
+ xml = fixture_file('text_node_with_comment.xml')
1147
+ text_node = TextNodeWithComment.parse(xml, single: true)
1148
+
1149
+ expect(text_node.value).to eq "With Comment"
1150
+ end
1151
+ end
1152
+
1137
1153
  end
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.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Le Berrigaud
@@ -10,10 +10,12 @@ authors:
10
10
  - Roland Swingler
11
11
  - Etienne Vallette d'Osia
12
12
  - Franklin Webber
13
+ - Benoist Claassen
14
+ - Johnny Dongelmans
13
15
  autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
- date: 2015-11-23 00:00:00.000000000 Z
18
+ date: 2021-08-14 00:00:00.000000000 Z
17
19
  dependencies:
18
20
  - !ruby/object:Gem::Dependency
19
21
  name: nokogiri
@@ -21,14 +23,14 @@ dependencies:
21
23
  requirements:
22
24
  - - "~>"
23
25
  - !ruby/object:Gem::Version
24
- version: '1.5'
26
+ version: '1.11'
25
27
  type: :runtime
26
28
  prerelease: false
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
29
31
  - - "~>"
30
32
  - !ruby/object:Gem::Version
31
- version: '1.5'
33
+ version: '1.11'
32
34
  - !ruby/object:Gem::Dependency
33
35
  name: rspec
34
36
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +47,7 @@ dependencies:
45
47
  version: '2.8'
46
48
  description: Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's
47
49
  Happymapper)
48
- email: bclaassen@digidentity.eu
50
+ email: jdongelmans@digidentity.com
49
51
  executables: []
50
52
  extensions: []
51
53
  extra_rdoc_files:
@@ -90,6 +92,7 @@ files:
90
92
  - spec/fixtures/set_config_options.xml
91
93
  - spec/fixtures/statuses.xml
92
94
  - spec/fixtures/subclass_namespace.xml
95
+ - spec/fixtures/text_node_with_comment.xml
93
96
  - spec/fixtures/unformatted_address.xml
94
97
  - spec/fixtures/wrapper.xml
95
98
  - spec/has_many_empty_array_spec.rb
@@ -109,7 +112,7 @@ files:
109
112
  - spec/xmlmapper_parse_spec.rb
110
113
  - spec/xmlmapper_spec.rb
111
114
  - spec/xpath_spec.rb
112
- homepage: http://github.com/digidentity/xmlmapper
115
+ homepage: https://github.com/digidentity/xmlmapper
113
116
  licenses:
114
117
  - MIT
115
118
  metadata: {}
@@ -121,17 +124,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
124
  requirements:
122
125
  - - ">="
123
126
  - !ruby/object:Gem::Version
124
- version: '0'
127
+ version: 2.5.0
125
128
  required_rubygems_version: !ruby/object:Gem::Requirement
126
129
  requirements:
127
130
  - - ">="
128
131
  - !ruby/object:Gem::Version
129
132
  version: '0'
130
133
  requirements: []
131
- rubyforge_project:
132
- rubygems_version: 2.5.1
134
+ rubygems_version: 3.1.4
133
135
  signing_key:
134
- specification_version: 3
136
+ specification_version: 4
135
137
  summary: Provides a simple way to map XML to Ruby Objects and back again.
136
138
  test_files:
137
139
  - spec/attribute_default_value_spec.rb
@@ -162,6 +164,7 @@ test_files:
162
164
  - spec/fixtures/set_config_options.xml
163
165
  - spec/fixtures/statuses.xml
164
166
  - spec/fixtures/subclass_namespace.xml
167
+ - spec/fixtures/text_node_with_comment.xml
165
168
  - spec/fixtures/unformatted_address.xml
166
169
  - spec/fixtures/wrapper.xml
167
170
  - spec/has_many_empty_array_spec.rb