ruby-changes:47284
From: nagachika <ko1@a...>
Date: Sun, 23 Jul 2017 16:33:12 +0900 (JST)
Subject: [ruby-changes:47284] nagachika:r59399 (ruby_2_4): merge revision(s) 59033, 59034: [Backport #13636]
nagachika 2017-07-23 16:33:07 +0900 (Sun, 23 Jul 2017) New Revision: 59399 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59399 Log: merge revision(s) 59033,59034: [Backport #13636] rexml: add close tag check on end of document to StreamParser [ruby-core:81593] [Bug #13636] Reported by Anton Sivakov. Thanks!!! * properties. Added files: branches/ruby_2_4/test/rexml/parser/test_stream.rb Modified directories: branches/ruby_2_4/ Modified files: branches/ruby_2_4/lib/rexml/parsers/streamparser.rb branches/ruby_2_4/version.h Index: ruby_2_4/test/rexml/parser/test_stream.rb =================================================================== --- ruby_2_4/test/rexml/parser/test_stream.rb (nonexistent) +++ ruby_2_4/test/rexml/parser/test_stream.rb (revision 59399) @@ -0,0 +1,32 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/rexml/parser/test_stream.rb#L1 +require "test/unit" +require "rexml/document" +require "rexml/streamlistener" + +module REXMLTests + class TestStreamParser < Test::Unit::TestCase + class NullListener + include REXML::StreamListener + end + + class TestInvalid < self + def test_no_end_tag + xml = "<root><sub>" + exception = assert_raise(REXML::ParseException) do + parse(xml) + end + assert_equal(<<-MESSAGE, exception.to_s) +Missing end tag for '/root/sub' +Line: 1 +Position: #{xml.bytesize} +Last 80 unconsumed characters: + MESSAGE + end + + private + def parse(xml, listener=nil) + listener ||= NullListener.new + REXML::Document.parse_stream(xml, listener) + end + end + end +end Property changes on: ruby_2_4/test/rexml/parser/test_stream.rb ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: ruby_2_4/lib/rexml/parsers/streamparser.rb =================================================================== --- ruby_2_4/lib/rexml/parsers/streamparser.rb (revision 59398) +++ ruby_2_4/lib/rexml/parsers/streamparser.rb (revision 59399) @@ -7,6 +7,7 @@ module REXML https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/rexml/parsers/streamparser.rb#L7 def initialize source, listener @listener = listener @parser = BaseParser.new( source ) + @tag_stack = [] end def add_listener( listener ) @@ -19,14 +20,21 @@ module REXML https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/rexml/parsers/streamparser.rb#L20 event = @parser.pull case event[0] when :end_document + unless @tag_stack.empty? + tag_path = "/" + @tag_stack.join("/") + raise ParseException.new("Missing end tag for '#{tag_path}'", + @parser.source) + end return when :start_element + @tag_stack << event[1] attrs = event[2].each do |n, v| event[2][n] = @parser.unnormalize( v ) end @listener.tag_start( event[1], attrs ) when :end_element @listener.tag_end( event[1] ) + @tag_stack.pop when :text normalized = @parser.unnormalize( event[1] ) @listener.text( normalized ) Index: ruby_2_4/version.h =================================================================== --- ruby_2_4/version.h (revision 59398) +++ ruby_2_4/version.h (revision 59399) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1 #define RUBY_VERSION "2.4.2" #define RUBY_RELEASE_DATE "2017-07-23" -#define RUBY_PATCHLEVEL 150 +#define RUBY_PATCHLEVEL 151 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 7 Index: ruby_2_4 =================================================================== --- ruby_2_4 (revision 59398) +++ ruby_2_4 (revision 59399) Property changes on: ruby_2_4 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r59033-59034 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/