Skip to content

Fix IOSource#readline for @pending_buffer #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def initialize( source )
@entity_expansion_count = 0
@entity_expansion_limit = Security.entity_expansion_limit
@entity_expansion_text_limit = Security.entity_expansion_text_limit
@source.ensure_buffer
end

def add_listener( listener )
Expand Down
7 changes: 6 additions & 1 deletion lib/rexml/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,19 @@ def current_line

private
def readline(term = nil)
str = @source.readline(term || @line_break)
if @pending_buffer
begin
str = @source.readline(term || @line_break)
rescue IOError
end
if str.nil?
str = @pending_buffer
else
str = @pending_buffer + str
end
@pending_buffer = nil
else
str = @source.readline(term || @line_break)
end
return nil if str.nil?

Expand Down
17 changes: 17 additions & 0 deletions test/parse/test_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
module REXMLTests
class TestParseText < Test::Unit::TestCase
class TestInvalid < self
def test_text_only
exception = assert_raise(REXML::ParseException) do
parser = REXML::Parsers::BaseParser.new('a')
while parser.has_next?
parser.pull
end
end

assert_equal(<<~DETAIL.chomp, exception.to_s)
Malformed XML: Content at the start of the document (got 'a')
Line: 1
Position: 1
Last 80 unconsumed characters:

DETAIL
end

def test_before_root
exception = assert_raise(REXML::ParseException) do
parser = REXML::Parsers::BaseParser.new('b<a></a>')
Expand Down
Loading