Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix that Hash#to_xml and Array#to_xml shouldn't modify their options …

…hashes [#672 state:resolved] [David Burger, Dana Jones]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit c9d4bcf16337241cc270eddb402b17cc094c609e 1 parent 2c4f4a8
David Burger authored lifo committed
View
1  activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -163,6 +163,7 @@ def to_xml(options = {})
raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml }
require 'builder' unless defined?(Builder)
+ options = options.dup
options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
options[:children] ||= options[:root].singularize
options[:indent] ||= 2
View
1  activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -99,6 +99,7 @@ def to_query(namespace = nil)
def to_xml(options = {})
require 'builder' unless defined?(Builder)
+ options = options.dup
options[:indent] ||= 2
options.reverse_merge!({ :builder => Builder::XmlMarkup.new(:indent => options[:indent]),
:root => "hash" })
View
7 activesupport/test/core_ext/array_ext_test.rb
@@ -233,6 +233,13 @@ def test_to_xml
assert xml.include?(%(<name>Jason</name>)), xml
end
+ def test_to_xml_dups_options
+ options = {:skip_instruct => true}
+ [].to_xml(options)
+ # :builder, etc, shouldn't be added to options
+ assert_equal({:skip_instruct => true}, options)
+ end
+
def test_to_xml_with_dedicated_name
xml = [
{ :name => "David", :age => 26, :age_in_millis => 820497600000 }, { :name => "Jason", :age => 31 }
View
7 activesupport/test/core_ext/hash_ext_test.rb
@@ -899,6 +899,13 @@ def test_roundtrip_to_xml_from_xml
assert_equal hash, Hash.from_xml(hash.to_xml(@xml_options))['person']
end
+ def test_to_xml_dups_options
+ options = {:skip_instruct => true}
+ {}.to_xml(options)
+ # :builder, etc, shouldn't be added to options
+ assert_equal({:skip_instruct => true}, options)
+ end
+
def test_datetime_xml_type_with_utc_time
alert_xml = <<-XML
<alert>
Please sign in to comment.
Something went wrong with that request. Please try again.