Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: missing namespaces #2

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--format progress --color
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Saml'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('README.md')
rdoc.rdoc_files.include('lib/**/*.rb')
end

Expand Down
12 changes: 7 additions & 5 deletions lib/xmlmapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -687,14 +687,16 @@ def to_xml(builder = nil, default_namespace = nil, namespace_override = nil,
# an empty element will be written to the xml
#
if value.nil? && element.options[:single] && element.options[:state_when_nil]
# NOTE In JRuby 9.0.4.0+ and Nokogiri version 1.6.8, Nokogiri::XML::Builder::NodeBuilder
# does not retain the XML namespace prefix for an element when adding an element
# to a parent node.
#
# NOTE
# In JRuby 9.0.4.0+ and Nokogiri version 1.6.8 or with Nokogiri version >= 1.12.0 (libxml >= 2.9.12),
# the Nokogiri::XML::Builder::NodeBuilder does not retain the XML namespace prefix for an element
# when adding an element to a parent node.
#
# The namespace prefix must be specified when adding the node to its parent.
# This issue manifests when setting an element's :state_when_nil' option to true.
#
# This JRuby workaround is intended for XML element prefixes that originate from a
# This workaround is intended for XML element prefixes that originate from a
# single namespace defined in 'registered_namespaces'. If there are
# multiple namespaces defined in the 'registered_namespaces' array,
# then the first namespace is selected.
Expand All @@ -707,7 +709,7 @@ def to_xml(builder = nil, default_namespace = nil, namespace_override = nil,
# 3. Adding namespace-less node to namespaced parent attaches the parent namespace to the child
# https://github.com/sparklemotion/nokogiri/issues/425
#
if RUBY_ENGINE == 'jruby' && !registered_namespaces.empty?
if (RUBY_ENGINE == 'jruby' || Nokogiri.uses_libxml?('>= 2.9.12')) && !registered_namespaces.empty?
ns = registered_namespaces.keys.first.to_sym
xml[ns].send("#{tag}_","")
else
Expand Down
2 changes: 1 addition & 1 deletion lib/xmlmapper/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module XmlMapper
VERSION = "0.7.3"
VERSION = '0.8.0'.freeze
end