File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,7 @@ def initialize( source )
167167@entity_expansion_count = 0
168168@entity_expansion_limit = Security . entity_expansion_limit
169169@entity_expansion_text_limit = Security . entity_expansion_text_limit
170+ @source . ensure_buffer
170171end
171172
172173def add_listener ( listener )
Original file line number Diff line number Diff line change @@ -295,14 +295,19 @@ def current_line
295295
296296private
297297def readline ( term = nil )
298- str = @source . readline ( term || @line_break )
299298if @pending_buffer
299+ begin
300+ str = @source . readline ( term || @line_break )
301+ rescue IOError
302+ end
300303if str . nil?
301304str = @pending_buffer
302305else
303306str = @pending_buffer + str
304307end
305308@pending_buffer = nil
309+ else
310+ str = @source . readline ( term || @line_break )
306311end
307312return nil if str . nil?
308313
Original file line number Diff line number Diff line change 44module REXMLTests
55class TestParseText < Test ::Unit ::TestCase
66class TestInvalid < self
7+ def test_text_only
8+ exception = assert_raise ( REXML ::ParseException ) do
9+ parser = REXML ::Parsers ::BaseParser . new ( 'a' )
10+ while parser . has_next?
11+ parser . pull
12+ end
13+ end
14+
15+ assert_equal ( <<~DETAIL . chomp , exception . to_s )
16+ Malformed XML: Content at the start of the document (got 'a')
17+ Line: 1
18+ Position: 1
19+ Last 80 unconsumed characters:
20+
21+ DETAIL
22+ end
23+
724def test_before_root
825exception = assert_raise ( REXML ::ParseException ) do
926parser = REXML ::Parsers ::BaseParser . new ( 'b<a></a>' )
You can’t perform that action at this time.
0 commit comments