read boundaries could break a multi-character gets terminator

This commit is contained in:
Justin Love 2012-08-29 19:11:23 -05:00
parent 7bd96f53b8
commit 3406ad49cd
2 changed files with 13 additions and 1 deletions

View File

@ -83,7 +83,7 @@ module IOExtras #:nodoc:
bufferIndex = 0
while ((matchIndex = @outputBuffer.index(aSepString, bufferIndex)) == nil)
bufferIndex = @outputBuffer.bytesize
bufferIndex = [bufferIndex, @outputBuffer.bytesize - aSepString.bytesize].max
if input_finished?
return @outputBuffer.empty? ? nil : flush
end

View File

@ -75,6 +75,18 @@ class AbstractInputStreamTest < Test::Unit::TestCase
assert_equal("o world#{$/}this is the second l", @io.gets("d l"))
end
LONG_LINES = [
'x'*48 + "\r\n",
'y'*49 + "\r\n",
'rest',
]
def test_getsMulitCharSeperator_split
io = TestAbstractInputStream.new(LONG_LINES.join)
assert_equal(LONG_LINES[0], io.gets("\r\n"))
assert_equal(LONG_LINES[1], io.gets("\r\n"))
assert_equal(LONG_LINES[2], io.gets("\r\n"))
end
def test_each_line
lineNumber=0
@io.each_line {