@@ -203,11 +192,11 @@ def test_with_only_default_entities
end
sax.parse
- expected_value = "#{'A' * @default_entity_expansion_text_limit}
"
+ expected_value = "#{'A' * REXML::Security.entity_expansion_text_limit}
"
assert_equal(expected_value, text_value.strip)
assert_equal(0, sax.entity_expansion_count)
assert do
- text_value.bytesize > @default_entity_expansion_text_limit
+ text_value.bytesize > REXML::Security.entity_expansion_text_limit
end
end
@@ -223,8 +212,8 @@ def test_entity_expansion_text_limit
&a;
XML
- REXML::Security.entity_expansion_text_limit = 90
sax = REXML::Parsers::SAX2Parser.new(source)
+ sax.entity_expansion_text_limit = 90
text_size = nil
sax.listen(:characters, ["member"]) do |text|
text_size = text.size
diff --git a/test/test_stream.rb b/test/test_stream.rb
index 782066c2..7917760a 100644
--- a/test/test_stream.rb
+++ b/test/test_stream.rb
@@ -126,16 +126,6 @@ def text(text)
end
class EntityExpansionLimitTest < Test::Unit::TestCase
- def setup
- @default_entity_expansion_limit = REXML::Security.entity_expansion_limit
- @default_entity_expansion_text_limit = REXML::Security.entity_expansion_text_limit
- end
-
- def teardown
- REXML::Security.entity_expansion_limit = @default_entity_expansion_limit
- REXML::Security.entity_expansion_text_limit = @default_entity_expansion_text_limit
- end
-
def test_have_value
source = <<-XML
@@ -172,18 +162,17 @@ def test_empty_value
XML
listener = MyListener.new
- REXML::Security.entity_expansion_limit = 100000
parser = REXML::Parsers::StreamParser.new( source, listener )
+ parser.entity_expansion_limit = 100000
parser.parse
assert_equal(11111, parser.entity_expansion_count)
- REXML::Security.entity_expansion_limit = @default_entity_expansion_limit
parser = REXML::Parsers::StreamParser.new( source, listener )
assert_raise(RuntimeError.new("number of entity expansions exceeded, processing aborted.")) do
parser.parse
end
assert do
- parser.entity_expansion_count > @default_entity_expansion_limit
+ parser.entity_expansion_count > REXML::Security.entity_expansion_limit
end
end
@@ -202,17 +191,19 @@ def test_with_default_entity
XML
listener = MyListener.new
- REXML::Security.entity_expansion_limit = 4
- REXML::Document.parse_stream(source, listener)
+ parser = REXML::Parsers::StreamParser.new( source, listener )
+ parser.entity_expansion_limit = 4
+ parser.parse
- REXML::Security.entity_expansion_limit = 3
+ parser = REXML::Parsers::StreamParser.new( source, listener )
+ parser.entity_expansion_limit = 3
assert_raise(RuntimeError.new("number of entity expansions exceeded, processing aborted.")) do
- REXML::Document.parse_stream(source, listener)
+ parser.parse
end
end
def test_with_only_default_entities
- member_value = "<p>#{'A' * @default_entity_expansion_text_limit}</p>"
+ member_value = "<p>#{'A' * REXML::Security.entity_expansion_text_limit}</p>"
source = <<-XML
@@ -231,11 +222,11 @@ def text(text)
parser = REXML::Parsers::StreamParser.new( source, listener )
parser.parse
- expected_value = "#{'A' * @default_entity_expansion_text_limit}
"
+ expected_value = "#{'A' * REXML::Security.entity_expansion_text_limit}
"
assert_equal(expected_value, listener.text_value.strip)
assert_equal(0, parser.entity_expansion_count)
assert do
- listener.text_value.bytesize > @default_entity_expansion_text_limit
+ listener.text_value.bytesize > REXML::Security.entity_expansion_text_limit
end
end
@@ -259,9 +250,9 @@ def text(text)
end
end
listener.text_value = ""
- REXML::Security.entity_expansion_text_limit = 90
- REXML::Document.parse_stream(source, listener)
-
+ parser = REXML::Parsers::StreamParser.new( source, listener )
+ parser.entity_expansion_text_limit = 90
+ parser.parse
assert_equal(90, listener.text_value.size)
end
end