diff options
Diffstat (limited to 'activesupport/lib/active_support/xml_mini/rexml.rb')
-rw-r--r-- | activesupport/lib/active_support/xml_mini/rexml.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/xml_mini/rexml.rb b/activesupport/lib/active_support/xml_mini/rexml.rb index 08f797749f..aaf4bb6bfd 100644 --- a/activesupport/lib/active_support/xml_mini/rexml.rb +++ b/activesupport/lib/active_support/xml_mini/rexml.rb @@ -15,13 +15,19 @@ module ActiveSupport # data:: # XML Document string or IO to parse def parse(data) - if data.respond_to?(:read) - data = data.read + if !data.respond_to?(:read) + data = StringIO.new(data || '') + end + + char = data.getc + if char.nil? + {} + else + data.ungetc(char) + require 'rexml/document' unless defined?(REXML::Document) + doc = REXML::Document.new(data) + merge_element!({}, doc.root) end - - require 'rexml/document' unless defined?(REXML::Document) - doc = REXML::Document.new(data) - merge_element!({}, doc.root) end private |