M src/rexml/source.rb +2 -2
@@ 147,7 147,7 @@ module REXML
# the XML spec. If there is one, we can determine the encoding from
# it.
@buffer = ""
- str = @source.read( 2 )
+ str = @source.read( 2 ) || ''
if encoding
self.encoding = encoding
elsif str[0,2] == "\xfe\xff"
@@ 161,7 161,7 @@ module REXML
else
@line_break = ">"
end
- super str+@source.readline( @line_break )
+ super( @source.eof? ? str : str+@source.readline( @line_break ) )
end
def scan(pattern, cons=false)
M test/core_test.rb +4 -0
@@ 1347,4 1347,8 @@ ENDXML
assert_equal "<item name='foo'>text</item>",
doc.root.elements["item[@name='foo']"].to_s
end
+
+ def test_empty_doc
+ assert(REXML::Document.new('').children.empty?)
+ end
end