1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@59239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2017-06-30 12:58:41 +00:00
parent 79e239cbd8
commit 971b99f3ed
4 changed files with 47 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Fri Jun 30 21:57:27 2017 Kouhei Sutou <kou@cozmixng.org>
* lib/rexml/parsers/streamparser.rb: add close tag check on end of
document to StreamParser [Bug #13636]
Reported by Anton Sivakov. Thanks!!!
Fri Jun 30 21:54:01 2017 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (rb_ary_insert): check position to insert even if no elements

View file

@ -7,6 +7,7 @@ module REXML
def initialize source, listener
@listener = listener
@parser = BaseParser.new( source )
@tag_stack = []
end
def add_listener( listener )
@ -19,14 +20,21 @@ module REXML
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 )

View file

@ -0,0 +1,32 @@
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

View file

@ -1,6 +1,6 @@
#define RUBY_VERSION "2.3.5"
#define RUBY_RELEASE_DATE "2017-06-30"
#define RUBY_PATCHLEVEL 335
#define RUBY_PATCHLEVEL 336
#define RUBY_RELEASE_YEAR 2017
#define RUBY_RELEASE_MONTH 6