Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug that Stream parser doesn't expand the user-defined entity r…
…eferences for "text" ## Why? Pull parser expands character references and predefined entity references, but doesn't expand user-defined entity references. ## Change - text_stream_unnormalize.rb ``` $LOAD_PATH.unshift(File.expand_path("lib")) require 'rexml/document' require 'rexml/parsers/sax2parser' require 'rexml/parsers/pullparser' require 'rexml/parsers/streamparser' require 'rexml/streamlistener' xml = <<EOS <!DOCTYPE foo [ <!ENTITY la "1234"> <!ENTITY lala "--&la;--"> <!ENTITY lalal "&la;&la;"> ]><root><la>&la;</la><lala>&lala;</lala><a><P> <I> <B> Text </B> </I></a><b>test™</b></root> EOS class StListener include REXML::StreamListener def text(text) puts text end end puts "REXML(DOM)" REXML::Document.new(xml).elements.each("/root/*") {|element| puts element.text} puts "" puts "REXML(Pull)" parser = REXML::Parsers::PullParser.new(xml) while parser.has_next? event = parser.pull case event.event_type when :text puts event[1] end end puts "" puts "REXML(Stream)" parser = REXML::Parsers::StreamParser.new(xml, StListener.new).parse puts "" puts "REXML(SAX)" sax = REXML::Parsers::SAX2Parser.new(xml) sax.listen(:characters) {|x| puts x } sax.parse ``` ## Before (master) ``` $ ruby text_stream_unnormalize.rb REXML(DOM) 1234 --1234-- <P> <I> <B> Text </B> </I> test™ REXML(Pull) 1234 --1234-- <P> <I> <B> Text </B> </I> test™ REXML(Stream) &la; #<= This &lala; #<= This <P> <I> <B> Text </B> </I> test™ REXML(SAX) 1234 --1234-- <P> <I> <B> Text </B> </I> test™ ``` After(This PR) ``` $ ruby text_stream_unnormalize.rb REXML(DOM) 1234 --1234-- <P> <I> <B> Text </B> </I> test™ REXML(Pull) 1234 --1234-- <P> <I> <B> Text </B> </I> test™ REXML(Stream) 1234 --1234-- <P> <I> <B> Text </B> </I> test™ REXML(SAX) 1234 --1234-- <P> <I> <B> Text </B> </I> test™ ```
- Loading branch information