diff options
author | Zachary Scott <mail@zzak.io> | 2015-06-18 09:03:07 -0400 |
---|---|---|
committer | Zachary Scott <mail@zzak.io> | 2015-06-18 09:03:07 -0400 |
commit | 8e9f57f6cd23ae4c092a9bcd608c7a5e56204dd3 (patch) | |
tree | 3e44d4243c1d6c592cd56bb5d378f5f0c3cb2055 /activesupport | |
parent | 5413c7903a5c99b9f9d781eb1bcb4a95ffa60411 (diff) | |
parent | 1bc7cb2d883a8261f3580e0c0b2b819bd4c054e6 (diff) | |
download | rails-8e9f57f6cd23ae4c092a9bcd608c7a5e56204dd3.tar.gz rails-8e9f57f6cd23ae4c092a9bcd608c7a5e56204dd3.tar.bz2 rails-8e9f57f6cd23ae4c092a9bcd608c7a5e56204dd3.zip |
Merge pull request #20575 from prathamesh-sonpatki/doc-xml-disallowed-types
Added documentation about passing custom disallowed types to Hash#from_xml [ci skip]
Diffstat (limited to 'activesupport')
-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 |