Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cf0fb9c

Browse filesBrowse files
authored
Fix IOSource#readline for @pending_buffer (#215)
## Why? Fixed a problem that `@pending_buffer` is not processed when `IOError` occurs in `@source.readline` although `@pending_buffer` exists when reading XML file.
1 parent 1d0c362 commit cf0fb9c
Copy full SHA for cf0fb9c

File tree

Expand file treeCollapse file tree

3 files changed

+24
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+24
-1
lines changed

‎lib/rexml/parsers/baseparser.rb

Copy file name to clipboardExpand all lines: lib/rexml/parsers/baseparser.rb
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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
170171
end
171172

172173
def add_listener( listener )

‎lib/rexml/source.rb

Copy file name to clipboardExpand all lines: lib/rexml/source.rb
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,19 @@ def current_line
295295

296296
private
297297
def readline(term = nil)
298-
str = @source.readline(term || @line_break)
299298
if @pending_buffer
299+
begin
300+
str = @source.readline(term || @line_break)
301+
rescue IOError
302+
end
300303
if str.nil?
301304
str = @pending_buffer
302305
else
303306
str = @pending_buffer + str
304307
end
305308
@pending_buffer = nil
309+
else
310+
str = @source.readline(term || @line_break)
306311
end
307312
return nil if str.nil?
308313

‎test/parse/test_text.rb

Copy file name to clipboardExpand all lines: test/parse/test_text.rb
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
module REXMLTests
55
class TestParseText < Test::Unit::TestCase
66
class 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+
724
def test_before_root
825
exception = assert_raise(REXML::ParseException) do
926
parser = REXML::Parsers::BaseParser.new('b<a></a>')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.