mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-10 04:41:15 -03:00
Make fish_indent stop panicing on closed stdin
Prior to this commit, this code:
fish_indent <&-
would panic as we would construct a File with a negative fd.
Check for a closed fd as other builtins do.
This commit is contained in:
@@ -1042,6 +1042,13 @@ enum OutputType {
|
||||
));
|
||||
return Err(STATUS_CMD_ERROR);
|
||||
}
|
||||
if streams.stdin_fd < 0 {
|
||||
let cmd = "fish_indent";
|
||||
streams
|
||||
.err
|
||||
.append(&wgettext_fmt!("%s: stdin is closed\n", cmd));
|
||||
return Err(STATUS_CMD_ERROR);
|
||||
}
|
||||
use std::os::fd::FromRawFd;
|
||||
let mut fd = unsafe { std::fs::File::from_raw_fd(streams.stdin_fd) };
|
||||
let mut buf = vec![];
|
||||
|
||||
@@ -652,3 +652,7 @@ cat $tmpdir/indent_test.fish
|
||||
# See that the builtin can be redirected
|
||||
printf %s\n a b c | builtin fish_indent | grep b
|
||||
# CHECK: b
|
||||
|
||||
# Regression test that fish_indent doesn't panic with closed stdin.
|
||||
fish_indent <&-
|
||||
# CHECKERR: fish_indent: stdin is closed
|
||||
|
||||
Reference in New Issue
Block a user