Merge pull request #61 from JustinLove/split_sep
read boundaries could break a multi-character gets terminator
This commit is contained in:
		
						commit
						a64b01fe96
					
				| 
						 | 
					@ -83,7 +83,7 @@ module IOExtras  #:nodoc:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      bufferIndex = 0
 | 
					      bufferIndex = 0
 | 
				
			||||||
      while ((matchIndex = @outputBuffer.index(aSepString, bufferIndex)) == nil)
 | 
					      while ((matchIndex = @outputBuffer.index(aSepString, bufferIndex)) == nil)
 | 
				
			||||||
        bufferIndex = @outputBuffer.bytesize
 | 
					        bufferIndex = [bufferIndex, @outputBuffer.bytesize - aSepString.bytesize].max
 | 
				
			||||||
        if input_finished?
 | 
					        if input_finished?
 | 
				
			||||||
          return @outputBuffer.empty? ? nil : flush
 | 
					          return @outputBuffer.empty? ? nil : flush
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,6 +75,18 @@ class AbstractInputStreamTest < Test::Unit::TestCase
 | 
				
			||||||
    assert_equal("o world#{$/}this is the second l", @io.gets("d l"))
 | 
					    assert_equal("o world#{$/}this is the second l", @io.gets("d l"))
 | 
				
			||||||
  end
 | 
					  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
 | 
					  def test_each_line
 | 
				
			||||||
    lineNumber=0
 | 
					    lineNumber=0
 | 
				
			||||||
    @io.each_line {
 | 
					    @io.each_line {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue