diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 98cc8a16354e0dd3c0a38b5a0b67b4261214f316..15974628bbb4d656de30a90ec5a0e84f0ee4474e 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* update XmlSimple to 1.0.10. Closes #6532. [nicksieger] + * Update dependencies to allow constants to be defined alongside their siblings. A common case for this is AR model classes with STI; user.rb might define User, Administrator and Guest for example. [Nicholas Seckar] * next_week respects DST changes. #6483, #5617, #2353, #2509, #4551 [marclove, rabiedenharn, rails@roetzel.de, jsolson@damogran.org, drbrain@segment7.net] diff --git a/activesupport/lib/active_support/vendor/xml_simple.rb b/activesupport/lib/active_support/vendor/xml_simple.rb index e6ce63a83963161f2110491ade17fc666fd18e4e..ec07966ff989dc37be88dbca094cf6c1674a4785 100644 --- a/activesupport/lib/active_support/vendor/xml_simple.rb +++ b/activesupport/lib/active_support/vendor/xml_simple.rb @@ -1,20 +1,21 @@ # = XmlSimple # # Author:: Maik Schmidt -# Copyright:: Copyright (c) 2003 Maik Schmidt +# Copyright:: Copyright (c) 2003-2006 Maik Schmidt # License:: Distributes under the same terms as Ruby. # require 'rexml/document' +require 'stringio' # Easy API to maintain XML (especially configuration files). -class XmlSimple #:nodoc: +class XmlSimple include REXML - @@VERSION = '1.0.2' + @@VERSION = '1.0.9' # A simple cache for XML documents that were already transformed # by xml_in. - class Cache #:nodoc: + class Cache # Creates and initializes a new Cache object. def initialize @mem_share_cache = {} @@ -184,7 +185,7 @@ def xml_in(string = nil, options = nil) @doc = load_xml_file(filename) end - elsif string.kind_of?(IO) + elsif string.kind_of?(IO) || string.kind_of?(StringIO) @doc = parse(string.readlines.to_s) else raise ArgumentError, "Could not parse object of type: <#{string.type}>." @@ -266,7 +267,7 @@ def XmlSimple.xml_out(hash, options = nil) keyattr keeproot forcecontent contentkey noattr searchpath forcearray suppressempty anonymoustag cache grouptags normalisespace normalizespace - variables varattr + variables varattr keytosymbol ), 'out' => %w( keyattr keeproot contentkey noattr rootname @@ -283,6 +284,7 @@ def XmlSimple.xml_out(hash, options = nil) DEF_ANONYMOUS_TAG = 'anon' DEF_FORCE_ARRAY = true DEF_INDENTATION = ' ' + DEF_KEY_TO_SYMBOL = false # Normalizes option names in a hash, i.e., turns all # characters to lower case and removes all underscores. @@ -350,6 +352,8 @@ def handle_options(direction, options) @options['xmldeclaration'] = DEF_XML_DECLARATION end + @options['keytosymbol'] = DEF_KEY_TO_SYMBOL unless @options.has_key?('keytosymbol') + if @options.has_key?('contentkey') if @options['contentkey'] =~ /^-(.*)$/ @options['contentkey'] = $1 @@ -654,6 +658,14 @@ def merge(hash, key, value) end end end + + #patch for converting keys to symbols + if @options.has_key?('keytosymbol') + if @options['keytosymbol'] == true + key = key.to_s.downcase.to_sym + end + end + if hash.has_key?(key) if hash[key].instance_of?(Array) hash[key] << value @@ -879,14 +891,7 @@ def hash_to_array(parent, hashref) # data:: # The string to be escaped. def escape_value(data) - return data if data.nil? || data == '' - result = data.dup - result.gsub!('&', '&') - result.gsub!('<', '<') - result.gsub!('>', '>') - result.gsub!('"', '"') - result.gsub!("'", ''') - result + Text::normalize(data) end # Removes leading and trailing whitespace and sequences of @@ -895,10 +900,7 @@ def escape_value(data) # text:: # String to be normalised. def normalise_space(text) - text.sub!(/^\s+/, '') - text.sub!(/\s+$/, '') - text.gsub!(/\s\s+/, ' ') - text + text.strip.gsub(/\s\s+/, ' ') end # Checks, if an object is nil, an empty String or an empty Hash. @@ -926,14 +928,14 @@ def empty(value) # default:: # Value to be returned, if node could not be converted. def node_to_text(node, default = nil) - if node.instance_of?(Element) - return node.texts.join('') - elsif node.instance_of?(Attribute) - return node.value.nil? ? default : node.value.strip - elsif node.instance_of?(Text) - return node.to_s.strip + if node.instance_of?(REXML::Element) + node.texts.map { |t| t.value }.join('') + elsif node.instance_of?(REXML::Attribute) + node.value.nil? ? default : node.value.strip + elsif node.instance_of?(REXML::Text) + node.value.strip else - return default + default end end