diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb index 99500072..8b8ba0da 100644 --- a/lib/rexml/source.rb +++ b/lib/rexml/source.rb @@ -272,7 +272,7 @@ def read_until(term) @scanner << readline(term) end if str - read if @scanner.eos? and !@source.eof? + read if @scanner.eos? and @source and !@source.eof? str else rest = @scanner.rest diff --git a/test/test_io_source.rb b/test/test_io_source.rb new file mode 100644 index 00000000..11776efc --- /dev/null +++ b/test/test_io_source.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: false + +require "rexml/source" + +module REXMLTests + class TestIOSource < Test::Unit::TestCase + def setup + @source = REXML::SourceFactory.create_from('') + end + + sub_test_case("#read_until") do + test("eof") do + assert_true(@source.read("nonexistent")) # Consume all data + assert_false(@source.read("nonexistent")) # Set EOF + assert_equal('', @source.read_until(">")) + end + end + end +end