mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-27 05:17:49 +08:00
commands: fix panic when stdin is empty for string args
License: MIT Signed-off-by: Jeromy <why@ipfs.io>
This commit is contained in:
parent
1eb94e64e3
commit
8a75a8cf08
@ -240,13 +240,19 @@ func (r *request) VarArgs(f func(string) error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var any bool
|
||||
scan := bufio.NewScanner(fi)
|
||||
for scan.Scan() {
|
||||
any = true
|
||||
err := f(scan.Text())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !any {
|
||||
return f("")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -39,4 +39,12 @@ test_expect_success "'ipfs block get' output looks good" '
|
||||
test_cmp expected_stat actual_stat
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs block stat' with nothing from stdin doesnt crash" '
|
||||
test_expect_code 1 ipfs block stat < /dev/null 2> stat_out
|
||||
'
|
||||
|
||||
test_expect_success "no panic in output" '
|
||||
test_expect_code 1 grep "panic" stat_out
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
Loading…
Reference in New Issue
Block a user