diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/mini.rb | 9 | ||||
-rw-r--r-- | activesupport/lib/active_support/xml_mini/nokogiri.rb | 34 | ||||
-rw-r--r-- | activesupport/test/xml_mini/nokogiri_engine_test.rb | 11 |
3 files changed, 24 insertions, 30 deletions
diff --git a/activesupport/lib/active_support/mini.rb b/activesupport/lib/active_support/mini.rb deleted file mode 100644 index b787650655..0000000000 --- a/activesupport/lib/active_support/mini.rb +++ /dev/null @@ -1,9 +0,0 @@ -$LOAD_PATH.unshift File.dirname(__FILE__) - -# whole object.rb pulls up rarely used introspection extensions -require "core_ext/object/blank" -require "core_ext/object/metaclass" -require 'core_ext/array' -require 'core_ext/hash' -require 'core_ext/module/attribute_accessors' -require 'core_ext/string/inflections' diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb index 847ab0152b..17bacd8441 100644 --- a/activesupport/lib/active_support/xml_mini/nokogiri.rb +++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb @@ -18,7 +18,7 @@ module ActiveSupport {} else data.ungetc(char) - doc = Nokogiri::XML(data) + doc = Nokogiri::XML(data) { |cfg| cfg.noblanks } raise doc.errors.first if doc.errors.length > 0 doc.to_hash end @@ -39,33 +39,25 @@ module ActiveSupport # hash:: # Hash to merge the converted element into. def to_hash(hash = {}) - hash[name] ||= attributes_as_hash + attributes = attributes_as_hash + if hash[name] + hash[name] = [hash[name]].flatten + hash[name] << attributes + else + hash[name] ||= attributes + end - walker = lambda { |memo, parent, child, callback| - next if child.blank? && 'file' != parent['type'] + children.each { |child| + next if child.blank? && 'file' != self['type'] - if child.text? - (memo[CONTENT_ROOT] ||= '') << child.content + if child.text? || child.cdata? + (attributes[CONTENT_ROOT] ||= '') << child.content next end - name = child.name - - child_hash = child.attributes_as_hash - if memo[name] - memo[name] = [memo[name]].flatten - memo[name] << child_hash - else - memo[name] = child_hash - end - - # Recursively walk children - child.children.each { |c| - callback.call(child_hash, child, c, callback) - } + child.to_hash attributes } - children.each { |c| walker.call(hash[name], self, c, walker) } hash end diff --git a/activesupport/test/xml_mini/nokogiri_engine_test.rb b/activesupport/test/xml_mini/nokogiri_engine_test.rb index 1eeff73d32..e16f36acee 100644 --- a/activesupport/test/xml_mini/nokogiri_engine_test.rb +++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb @@ -159,6 +159,17 @@ class NokogiriEngineTest < Test::Unit::TestCase XmlMini.parse(io) end + def test_children_with_cdata + assert_equal_rexml(<<-eoxml) + <root> + <products> + hello <![CDATA[everyone]]> + morning + </products> + </root> + eoxml + end + private def assert_equal_rexml(xml) hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) } |