ruby-changes:36364
From: kou <ko1@a...>
Date: Sat, 15 Nov 2014 20:45:39 +0900 (JST)
Subject: [ruby-changes:36364] kou:r48445 (trunk): * test/rexml/test_document.rb
kou 2014-11-15 20:45:27 +0900 (Sat, 15 Nov 2014) New Revision: 48445 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48445 Log: * test/rexml/test_document.rb (REXMLTests::TestDocument::EntityExpansionLimitTest): Define test XML in each test method because (1) each XML in used only one test and (2) related data and code should be close. Modified files: trunk/ChangeLog trunk/test/rexml/test_document.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 48444) +++ ChangeLog (revision 48445) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Nov 15 20:43:31 2014 Kouhei Sutou <kou@c...> + + * test/rexml/test_document.rb + (REXMLTests::TestDocument::EntityExpansionLimitTest): Define + test XML in each test method because (1) each XML in used only + one test and (2) related data and code should be close. + Sat Nov 15 20:39:06 2014 Kouhei Sutou <kou@c...> * test/rexml/test_document.rb Index: test/rexml/test_document.rb =================================================================== --- test/rexml/test_document.rb (revision 48444) +++ test/rexml/test_document.rb (revision 48445) @@ -41,7 +41,8 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/rexml/test_document.rb#L41 REXML::Security.entity_expansion_limit = @default_entity_expansion_limit end - XML_WITH_NESTED_ENTITY = <<EOF + def test_general_entity_have_value + xml = <<EOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE member [ <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"> @@ -57,7 +58,21 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/rexml/test_document.rb#L58 </member> EOF - XML_WITH_NESTED_EMPTY_ENTITY = <<EOF + doc = REXML::Document.new(xml) + assert_raise(RuntimeError) do + doc.root.children.first.value + end + REXML::Security.entity_expansion_limit = 100 + assert_equal(100, REXML::Security.entity_expansion_limit) + doc = REXML::Document.new(xml) + assert_raise(RuntimeError) do + doc.root.children.first.value + end + assert_equal(101, doc.entity_expansion_count) + end + + def test_general_entity_empty_value + xml = <<EOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE member [ <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"> @@ -73,35 +88,21 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/rexml/test_document.rb#L88 </member> EOF - XML_WITH_NESTED_PARAMETER_ENTITY = <<EOF -<!DOCTYPE root [ - <!ENTITY % a "BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM."> - <!ENTITY % b "%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;"> - <!ENTITY % c "%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;"> - <!ENTITY % d "%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;"> - <!ENTITY % e "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;"> - <!ENTITY % f "%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;"> - <!ENTITY % g "%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;"> - <!ENTITY test "test %g;"> -]> -<cd></cd> -EOF - - XML_WITH_NESTED_EMPTY_PARAMETER_ENTITY = <<EOF -<!DOCTYPE root [ - <!ENTITY % a ""> - <!ENTITY % b "%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;"> - <!ENTITY % c "%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;"> - <!ENTITY % d "%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;"> - <!ENTITY % e "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;"> - <!ENTITY % f "%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;"> - <!ENTITY % g "%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;"> - <!ENTITY test "test %g;"> -]> -<cd></cd> -EOF + doc = REXML::Document.new(xml) + assert_raise(RuntimeError) do + doc.root.children.first.value + end + REXML::Security.entity_expansion_limit = 100 + assert_equal(100, REXML::Security.entity_expansion_limit) + doc = REXML::Document.new(xml) + assert_raise(RuntimeError) do + doc.root.children.first.value + end + assert_equal(101, doc.entity_expansion_count) + end - XML_WITH_4_ENTITY_EXPANSION = <<EOF + def test_general_entity_with_default_entity + xml = <<EOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE member [ <!ENTITY a "a"> @@ -114,64 +115,63 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/rexml/test_document.rb#L115 </member> EOF - def test_general_entity_have_value - doc = REXML::Document.new(XML_WITH_NESTED_ENTITY) - assert_raise(RuntimeError) do - doc.root.children.first.value - end - REXML::Security.entity_expansion_limit = 100 - assert_equal(100, REXML::Security.entity_expansion_limit) - doc = REXML::Document.new(XML_WITH_NESTED_ENTITY) - assert_raise(RuntimeError) do - doc.root.children.first.value - end - assert_equal(101, doc.entity_expansion_count) - end - - def test_general_entity_empty_value - doc = REXML::Document.new(XML_WITH_NESTED_EMPTY_ENTITY) - assert_raise(RuntimeError) do - doc.root.children.first.value - end - REXML::Security.entity_expansion_limit = 100 - assert_equal(100, REXML::Security.entity_expansion_limit) - doc = REXML::Document.new(XML_WITH_NESTED_EMPTY_ENTITY) - assert_raise(RuntimeError) do - doc.root.children.first.value - end - assert_equal(101, doc.entity_expansion_count) - end - - def test_general_entity_with_default_entity REXML::Security.entity_expansion_limit = 4 - doc = REXML::Document.new(XML_WITH_4_ENTITY_EXPANSION) + doc = REXML::Document.new(xml) assert_equal("\na\na a\n<\n", doc.root.children.first.value) REXML::Security.entity_expansion_limit = 3 - doc = REXML::Document.new(XML_WITH_4_ENTITY_EXPANSION) + doc = REXML::Document.new(xml) assert_raise(RuntimeError) do doc.root.children.first.value end end def test_parameter_entity_have_value + xml = <<EOF +<!DOCTYPE root [ + <!ENTITY % a "BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM."> + <!ENTITY % b "%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;"> + <!ENTITY % c "%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;"> + <!ENTITY % d "%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;"> + <!ENTITY % e "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;"> + <!ENTITY % f "%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;"> + <!ENTITY % g "%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;"> + <!ENTITY test "test %g;"> +]> +<cd></cd> +EOF + assert_raise(REXML::ParseException) do - REXML::Document.new(XML_WITH_NESTED_PARAMETER_ENTITY) + REXML::Document.new(xml) end REXML::Security.entity_expansion_limit = 100 assert_equal(100, REXML::Security.entity_expansion_limit) assert_raise(REXML::ParseException) do - REXML::Document.new(XML_WITH_NESTED_PARAMETER_ENTITY) + REXML::Document.new(xml) end end def test_parameter_entity_empty_value + xml = <<EOF +<!DOCTYPE root [ + <!ENTITY % a ""> + <!ENTITY % b "%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;"> + <!ENTITY % c "%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;"> + <!ENTITY % d "%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;"> + <!ENTITY % e "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;"> + <!ENTITY % f "%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;"> + <!ENTITY % g "%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;"> + <!ENTITY test "test %g;"> +]> +<cd></cd> +EOF + assert_raise(REXML::ParseException) do - REXML::Document.new(XML_WITH_NESTED_EMPTY_PARAMETER_ENTITY) + REXML::Document.new(xml) end REXML::Security.entity_expansion_limit = 100 assert_equal(100, REXML::Security.entity_expansion_limit) assert_raise(REXML::ParseException) do - REXML::Document.new(XML_WITH_NESTED_EMPTY_PARAMETER_ENTITY) + REXML::Document.new(xml) end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/