From b9e021df974217b9c6ee273bd6c98b40ebde0cd3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 10 Mar 2009 20:45:14 -0700 Subject: adding more nokogiri tests and making the main rails tests pass [#2190 state:resolved] Signed-off-by: Jeremy Kemper --- .../lib/active_support/xml_mini/nokogiri.rb | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb index 5c8a6bfe89..10281584fc 100644 --- a/activesupport/lib/active_support/xml_mini/nokogiri.rb +++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb @@ -1,3 +1,5 @@ +require 'nokogiri' + # = XmlMini Nokogiri implementation module ActiveSupport module XmlMini_Nokogiri #:nodoc: @@ -10,7 +12,9 @@ module ActiveSupport if string.blank? {} else - Nokogiri::XML(string).to_hash + doc = Nokogiri::XML(string) + raise doc.errors.first if doc.errors.length > 0 + doc.to_hash end end @@ -31,8 +35,8 @@ module ActiveSupport def to_hash(hash = {}) hash[name] ||= attributes_as_hash - walker = lambda { |child, memo, callback| - next if child.blank? + walker = lambda { |memo, parent, child, callback| + next if child.blank? && 'file' != parent['type'] if child.text? (memo[CONTENT_ROOT] ||= '') << child.content @@ -41,18 +45,21 @@ module ActiveSupport name = child.name + child_hash = child.attributes_as_hash if memo[name] memo[name] = [memo[name]].flatten - memo[name] << child.attributes_as_hash + memo[name] << child_hash else - memo[name] = child.attributes_as_hash + memo[name] = child_hash end # Recusively walk children - child.children.each { |c| callback.call(c, memo[name], callback) } + child.children.each { |c| + callback.call(child_hash, child, c, callback) + } } - children.each { |c| walker.call(c, hash[name], walker) } + children.each { |c| walker.call(hash[name], self, c, walker) } hash end -- cgit v1.2.3