diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-03-10 20:45:14 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-03-10 22:11:15 -0700 |
commit | b9e021df974217b9c6ee273bd6c98b40ebde0cd3 (patch) | |
tree | 617537e481d5a2a2beaffc992679e3747676de9e /activesupport/test/xml_mini/nokogiri_engine_test.rb | |
parent | fa45540cdb30cee44983c9121e3ebfc317d21668 (diff) | |
download | rails-b9e021df974217b9c6ee273bd6c98b40ebde0cd3.tar.gz rails-b9e021df974217b9c6ee273bd6c98b40ebde0cd3.tar.bz2 rails-b9e021df974217b9c6ee273bd6c98b40ebde0cd3.zip |
adding more nokogiri tests and making the main rails tests pass
[#2190 state:resolved]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/test/xml_mini/nokogiri_engine_test.rb')
-rw-r--r-- | activesupport/test/xml_mini/nokogiri_engine_test.rb | 47 |
1 files changed, 47 insertions, 0 deletions
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) + <blog> + <logo type="file" name="logo.png" content_type="image/png"> + </logo> + </blog> + 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 + <?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE member [ + <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"> + <!ENTITY b "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;"> + <!ENTITY c "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;"> + <!ENTITY d "&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;"> + <!ENTITY e "&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;"> + <!ENTITY f "&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;"> + <!ENTITY g "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"> + ]> + <member> + &a; + </member> + 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) + <blog> + <posts type="array"> + <post>a post</post> + <post>another post</post> + </posts> + </blog> + eoxml + end + def test_one_node_document_as_hash assert_equal_rexml(<<-eoxml) <products/> |