aboutsummaryrefslogtreecommitdiffstats
path: root/test/rexml
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-22 09:35:46 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-22 09:35:46 +0000
commit1ad9075734a7fd9d58920c714953ec851efcae6b (patch)
tree58aebc91254ba8f04466e3569349dfca9f0aaea9 /test/rexml
parent7dd6e08b93a750d962fee51eeaec726caf8dc82e (diff)
downloadruby-1ad9075734a7fd9d58920c714953ec851efcae6b.tar.gz
* lib/rexml/document.rb (REXML::Document.entity_expansion_text_limit):
new attribute to read/write entity expansion text limit. the default limit is 10Kb. * lib/rexml/text.rb (REXML::Text.unnormalize): check above attribute. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rexml')
-rw-r--r--test/rexml/test_entity.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/rexml/test_entity.rb b/test/rexml/test_entity.rb
index e6d6f29007..5900fac7a8 100644
--- a/test/rexml/test_entity.rb
+++ b/test/rexml/test_entity.rb
@@ -104,6 +104,24 @@ class EntityTester < Test::Unit::TestCase
assert_equal source, out
end
+ def test_entity_string_limit
+ template = '<!DOCTYPE bomb [ <!ENTITY a "^" > ]> <bomb>$</bomb>'
+ len = 5120 # 5k per entity
+ template.sub!(/\^/, "B" * len)
+
+ # 10k is OK
+ entities = '&a;' * 2 # 5k entity * 2 = 10k
+ xmldoc = REXML::Document.new(template.sub(/\$/, entities))
+ assert_equal(len * 2, xmldoc.root.text.bytesize)
+
+ # above 10k explodes
+ entities = '&a;' * 3 # 5k entity * 2 = 15k
+ xmldoc = REXML::Document.new(template.sub(/\$/, entities))
+ assert_raises(RuntimeError) do
+ xmldoc.root.text
+ end
+ end
+
def test_raw
source = '<!DOCTYPE foo [
<!ENTITY ent "replace">