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 --- activesupport/test/core_ext/hash_ext_test.rb | 7 +++- .../test/xml_mini/nokogiri_engine_test.rb | 47 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 2285d5a724..80582cd9c9 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -884,7 +884,12 @@ class QueryTest < Test::Unit::TestCase end def test_expansion_count_is_limited - expected = defined?(LibXML) ? LibXML::XML::Error : RuntimeError + expected = { + 'ActiveSupport::XmlMini_REXML' => 'RuntimeError', + 'ActiveSupport::XmlMini_Nokogiri' => 'Nokogiri::XML::SyntaxError', + 'ActiveSupport::XmlMini_LibXML' => 'LibXML::XML::Error', + }[ActiveSupport::XmlMini.backend.name].constantize + assert_raise expected do attack_xml = <<-EOT diff --git a/activesupport/test/xml_mini/nokogiri_engine_test.rb b/activesupport/test/xml_mini/nokogiri_engine_test.rb index 1ab36785ac..e5174a0b57 100644 --- a/activesupport/test/xml_mini/nokogiri_engine_test.rb +++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb @@ -21,6 +21,42 @@ class NokogiriEngineTest < Test::Unit::TestCase XmlMini.backend = @default_backend end + def test_file_from_xml + hash = Hash.from_xml(<<-eoxml) + + + + + eoxml + assert hash.has_key?('blog') + assert hash['blog'].has_key?('logo') + + file = hash['blog']['logo'] + assert_equal 'logo.png', file.original_filename + assert_equal 'image/png', file.content_type + end + + def test_exception_thrown_on_expansion_attack + assert_raise Nokogiri::XML::SyntaxError do + attack_xml = <<-EOT + + + + + + + + + ]> + + &a; + + EOT + Hash.from_xml(attack_xml) + end + end + def test_setting_nokogiri_as_backend XmlMini.backend = 'Nokogiri' assert_equal XmlMini_Nokogiri, XmlMini.backend @@ -31,6 +67,17 @@ class NokogiriEngineTest < Test::Unit::TestCase assert_equal({}, XmlMini.parse('')) end + def test_array_type_makes_an_array + assert_equal_rexml(<<-eoxml) + + + a post + another post + + + eoxml + end + def test_one_node_document_as_hash assert_equal_rexml(<<-eoxml) -- cgit v1.2.3