Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7086

Show
Ignore:
Timestamp:
06/23/07 00:40:53 (1 year ago)
Author:
bitsweat
Message:

Demote Hash#to_xml to use XmlSimple#xml_in_string so it can't read files or stdin. Closes #8453.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r7083 r7086  
    11*SVN* 
     2 
     3* Demote Hash#to_xml to use XmlSimple#xml_in_string so it can't read files or stdin.  #8453 [candlerb, Jeremy Kemper] 
    24 
    35* Backport clean_logger changes to support ruby 1.8.2 [mislav] 
  • trunk/activesupport/lib/active_support/core_ext/hash/conversions.rb

    r7085 r7086  
    1818  def to_query(key) #:nodoc: 
    1919    collect { |value| value.to_query("#{key}[]") } * '&' 
     20  end 
     21end 
     22 
     23# Locked down XmlSimple#xml_in_string 
     24class XmlSimple 
     25  # Same as xml_in but doesn't try to smartly shoot itself in the foot. 
     26  def xml_in_string(string, options = nil) 
     27    handle_options('in', options) 
     28 
     29    @doc = parse(string) 
     30    result = collapse(@doc.root) 
     31 
     32    if @options['keeproot'] 
     33      merge({}, @doc.root.name, result) 
     34    else 
     35      result 
     36    end 
     37  end 
     38 
     39  def self.xml_in_string(string, options = nil) 
     40    new.xml_in_string(string, options) 
    2041  end 
    2142end 
     
    136157          def from_xml(xml) 
    137158            # TODO: Refactor this into something much cleaner that doesn't rely on XmlSimple 
    138             typecast_xml_value(undasherize_keys(XmlSimple.xml_in(xml, 
     159            typecast_xml_value(undasherize_keys(XmlSimple.xml_in_string(xml, 
    139160              'forcearray'   => false, 
    140161              'forcecontent' => true,