diff --git a/lib/rexml/parsers/streamparser.rb b/lib/rexml/parsers/streamparser.rb
index e2da2a7d..7781fe44 100644
--- a/lib/rexml/parsers/streamparser.rb
+++ b/lib/rexml/parsers/streamparser.rb
@@ -7,12 +7,17 @@ class StreamParser
def initialize source, listener
@listener = listener
@parser = BaseParser.new( source )
+ @entities = {}
end
def add_listener( listener )
@parser.add_listener( listener )
end
+ def entity_expansion_count
+ @parser.entity_expansion_count
+ end
+
def parse
# entity string
while true
@@ -28,7 +33,7 @@ def parse
when :end_element
@listener.tag_end( event[1] )
when :text
- unnormalized = @parser.unnormalize( event[1] )
+ unnormalized = @parser.unnormalize( event[1], @entities )
@listener.text( unnormalized )
when :processing_instruction
@listener.instruction( *event[1,2] )
@@ -40,6 +45,7 @@ def parse
when :comment, :attlistdecl, :cdata, :xmldecl, :elementdecl
@listener.send( event[0].to_s, *event[1..-1] )
when :entitydecl, :notationdecl
+ @entities[ event[1] ] = event[2] if event.size == 3
@listener.send( event[0].to_s, event[1..-1] )
when :externalentity
entity_reference = event[1]
diff --git a/test/test_stream.rb b/test/test_stream.rb
index 615d497f..782066c2 100644
--- a/test/test_stream.rb
+++ b/test/test_stream.rb
@@ -87,6 +87,42 @@ def entity(content)
assert_equal(["ISOLat2"], listener.entities)
end
+
+ def test_entity_replacement
+ source = <<-XML
+
+
+
+]>
Text ", listener.text_value)
+ end
end
class EntityExpansionLimitTest < Test::Unit::TestCase
@@ -100,6 +136,81 @@ def teardown
REXML::Security.entity_expansion_text_limit = @default_entity_expansion_text_limit
end
+ def test_have_value
+ source = <<-XML
+
+
+
+
+
+
+]>
+
#{'A' * @default_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 end end + + def test_entity_expansion_text_limit + source = <<-XML + + + + + +]> +