diff options
author | Prathamesh Sonpatki <csonpatki@gmail.com> | 2015-06-16 14:11:44 +0530 |
---|---|---|
committer | Prathamesh Sonpatki <csonpatki@gmail.com> | 2015-06-18 18:29:02 +0530 |
commit | 1bc7cb2d883a8261f3580e0c0b2b819bd4c054e6 (patch) | |
tree | 2c684d280ae887f9be327e8271bb05d6cf0c0ce3 | |
parent | fcbd2e821e12fdf66ad2f28e97992a7cd75f529e (diff) | |
download | rails-1bc7cb2d883a8261f3580e0c0b2b819bd4c054e6.tar.gz rails-1bc7cb2d883a8261f3580e0c0b2b819bd4c054e6.tar.bz2 rails-1bc7cb2d883a8261f3580e0c0b2b819bd4c054e6.zip |
Added documentation about passing custom disallowed types to Hash#from_xml [ci skip]
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/conversions.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 2149d4439d..8594d9bf2e 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -106,7 +106,25 @@ class Hash # # => {"hash"=>{"foo"=>1, "bar"=>2}} # # +DisallowedType+ is raised if the XML contains attributes with <tt>type="yaml"</tt> or - # <tt>type="symbol"</tt>. Use <tt>Hash.from_trusted_xml</tt> to parse this XML. + # <tt>type="symbol"</tt>. Use <tt>Hash.from_trusted_xml</tt> to + # parse this XML. + # + # Custom +disallowed_types+ can also be passed in the form of an + # array. + # + # xml = <<-XML + # <?xml version="1.0" encoding="UTF-8"?> + # <hash> + # <foo type="integer">1</foo> + # <bar type="string">"David"</bar> + # </hash> + # XML + # + # hash = Hash.from_xml(xml, ['integer']) + # # => ActiveSupport::XMLConverter::DisallowedType: Disallowed type attribute: "integer" + # + # Note that passing custom disallowed types will override the default types, + # which are Symbol and YAML. def from_xml(xml, disallowed_types = nil) ActiveSupport::XMLConverter.new(xml, disallowed_types).to_h end |