From a38971c595a6a5ee6f4cf0b2c066311a4694a59c Mon Sep 17 00:00:00 2001 From: kou Date: Sat, 15 Nov 2014 11:45:27 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 ++ test/rexml/test_document.rb | 140 ++++++++++++++++++------------------ 2 files changed, 77 insertions(+), 70 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3dbab69915..2bfb9c16bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Nov 15 20:43:31 2014 Kouhei Sutou + + * 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 * test/rexml/test_document.rb diff --git a/test/rexml/test_document.rb b/test/rexml/test_document.rb index 8f37b2f12b..f4e78c9c03 100644 --- a/test/rexml/test_document.rb +++ b/test/rexml/test_document.rb @@ -41,7 +41,8 @@ EOF REXML::Security.entity_expansion_limit = @default_entity_expansion_limit end - XML_WITH_NESTED_ENTITY = < @@ -57,7 +58,21 @@ EOF EOF - XML_WITH_NESTED_EMPTY_ENTITY = < @@ -73,7 +88,45 @@ EOF EOF - XML_WITH_NESTED_PARAMETER_ENTITY = < + + +]> + +&a; +&a2; +< + +EOF + + REXML::Security.entity_expansion_limit = 4 + 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) + assert_raise(RuntimeError) do + doc.root.children.first.value + end + end + + def test_parameter_entity_have_value + xml = < @@ -87,7 +140,18 @@ EOF EOF - XML_WITH_NESTED_EMPTY_PARAMETER_ENTITY = < @@ -101,77 +165,13 @@ EOF EOF - XML_WITH_4_ENTITY_EXPANSION = < - - -]> - -&a; -&a2; -< - -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) - 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) - assert_raise(RuntimeError) do - doc.root.children.first.value - end - end - - def test_parameter_entity_have_value 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) - end - end - - def test_parameter_entity_empty_value - assert_raise(REXML::ParseException) do - REXML::Document.new(XML_WITH_NESTED_EMPTY_PARAMETER_ENTITY) - 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