From 179b4512d1e98c7657151b25f159262ea1860f52 Mon Sep 17 00:00:00 2001 From: Developer Date: Wed, 16 Sep 2009 14:12:13 -0400 Subject: [PATCH] Allow Nokogiri XmlMini backend to process cdata elements [#3219 state:committed] Signed-off-by: Jeremy Kemper --- activesupport/lib/active_support/xml_mini/nokogiri.rb | 2 +- activesupport/test/xml_mini/nokogiri_engine_test.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb index 10281584fc8dc..a77a7f9c4e77c 100644 --- a/activesupport/lib/active_support/xml_mini/nokogiri.rb +++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb @@ -38,7 +38,7 @@ def to_hash(hash = {}) walker = lambda { |memo, parent, child, callback| next if child.blank? && 'file' != parent['type'] - if child.text? + if child.text? || child.cdata? (memo[CONTENT_ROOT] ||= '') << child.content next end diff --git a/activesupport/test/xml_mini/nokogiri_engine_test.rb b/activesupport/test/xml_mini/nokogiri_engine_test.rb index e5174a0b57f8e..09989f2111e72 100644 --- a/activesupport/test/xml_mini/nokogiri_engine_test.rb +++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb @@ -147,6 +147,17 @@ def test_children_with_non_adjacent_text eoxml end + def test_children_with_cdata + assert_equal_rexml(<<-eoxml) + + + hello + morning + + + eoxml + end + private def assert_equal_rexml(xml) hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) }