mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-01-09 17:53:56 +00:00
Fix #248 - Premature termination of Reader on long input
This commit is contained in:
parent
fdbfe36c0b
commit
b00bcf506e
@ -30,9 +30,29 @@ func (r *Reader) ReadSource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) feed(src io.Reader) {
|
func (r *Reader) feed(src io.Reader) {
|
||||||
if scanner := bufio.NewScanner(src); scanner != nil {
|
reader := bufio.NewReader(src)
|
||||||
for scanner.Scan() {
|
eof := false
|
||||||
r.pusher(scanner.Text())
|
Loop:
|
||||||
|
for !eof {
|
||||||
|
buf := []byte{}
|
||||||
|
iter := 0 // TODO: max size?
|
||||||
|
for {
|
||||||
|
// "ReadLine either returns a non-nil line or it returns an error, never both"
|
||||||
|
line, isPrefix, err := reader.ReadLine()
|
||||||
|
eof = err == io.EOF
|
||||||
|
if eof {
|
||||||
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
break Loop
|
||||||
|
}
|
||||||
|
iter++
|
||||||
|
buf = append(buf, line...)
|
||||||
|
if !isPrefix {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if iter > 0 {
|
||||||
|
r.pusher(string(buf))
|
||||||
r.eventBox.Set(EvtReadNew, nil)
|
r.eventBox.Set(EvtReadNew, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -525,6 +525,17 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys 'uuu', 'TTT', 'tt', 'uu', 'ttt', 'C-j'
|
tmux.send_keys 'uuu', 'TTT', 'tt', 'uu', 'ttt', 'C-j'
|
||||||
assert_equal %w[4 5 6 9], readonce.split($/)
|
assert_equal %w[4 5 6 9], readonce.split($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_long_line
|
||||||
|
tempname = TEMPNAME + Time.now.to_f.to_s
|
||||||
|
data = '.' * 256 * 1024
|
||||||
|
File.open(tempname, 'w') do |f|
|
||||||
|
f << data
|
||||||
|
end
|
||||||
|
assert_equal data, `cat #{tempname} | #{FZF} -f .`.chomp
|
||||||
|
ensure
|
||||||
|
File.unlink tempname
|
||||||
|
end
|
||||||
private
|
private
|
||||||
def writelines path, lines
|
def writelines path, lines
|
||||||
File.unlink path while File.exists? path
|
File.unlink path while File.exists? path
|
||||||
|
Loading…
Reference in New Issue
Block a user