Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix handling of nil values with the pure-Java version of nokogiri in …

…the xml_serializer plugin

This is probably a regression in nokogiri compared to the libxml
version, but this new code works on both.  Also, the pure-Java
version seems to upcase the encoding attribute, but just change
the spec to use an upcased version as that isn't a big deal.
  • Loading branch information...
commit 1aaf41c1f45835fb89d92d7385ea0ebf6f233e6d 1 parent 90adf2e
Jeremy Evans authored
2  CHANGELOG
View
@@ -1,5 +1,7 @@
=== HEAD
+* Fix handling of nil values with the pure-Java version of nokogiri in the xml_serializer plugin (jeremyevans)
+
* Make identity_map plugin work with standard eager loading of many_to_many and many_through_many associations (jeremyevans)
* Make create_table! only attempt to drop the table if it already exists (jeremyevans)
4 lib/sequel/plugins/xml_serializer.rb
View
@@ -205,9 +205,9 @@ def from_xml_node(parent, opts={})
klass.from_xml_node(node)
end
elsif cols.include?(k)
- self[k.to_sym] = node[:nil] ? nil : node.children.first.to_s
+ self[k.to_sym] = node.key?('nil') ? nil : node.children.first.to_s
elsif meths.include?("#{k}=")
- send("#{k}=", node[:nil] ? nil : node.children.first.to_s)
+ send("#{k}=", node.key?('nil') ? nil : node.children.first.to_s)
else
raise Error, "Entry in XML not an association or column and no setter method exists: #{k}"
end
8 spec/extensions/xml_serializer_spec.rb
View
@@ -118,13 +118,13 @@ class Artist < Sequel::Model
end
it "should support an :encoding option when serializing" do
- ["<?xml version=\"1.0\" encoding=\"utf-8\"?><artist><id>2</id><name>YJM</name></artist>",
- "<?xml version=\"1.0\" encoding=\"utf-8\"?><artist><name>YJM</name><id>2</id></artist>"].should include(@artist.to_xml(:encoding=>'utf-8').gsub(/\n */m, ''))
+ ["<?xml version=\"1.0\" encoding=\"UTF-8\"?><artist><id>2</id><name>YJM</name></artist>",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><artist><name>YJM</name><id>2</id></artist>"].should include(@artist.to_xml(:encoding=>'UTF-8').gsub(/\n */m, ''))
end
it "should support a :builder_opts option when serializing" do
- ["<?xml version=\"1.0\" encoding=\"utf-8\"?><artist><id>2</id><name>YJM</name></artist>",
- "<?xml version=\"1.0\" encoding=\"utf-8\"?><artist><name>YJM</name><id>2</id></artist>"].should include(@artist.to_xml(:builder_opts=>{:encoding=>'utf-8'}).gsub(/\n */m, ''))
+ ["<?xml version=\"1.0\" encoding=\"UTF-8\"?><artist><id>2</id><name>YJM</name></artist>",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><artist><name>YJM</name><id>2</id></artist>"].should include(@artist.to_xml(:builder_opts=>{:encoding=>'UTF-8'}).gsub(/\n */m, ''))
end
it "should support an :types option when serializing" do
Please sign in to comment.
Something went wrong with that request. Please try again.