forked from extern/nushell
Fixed last command crash
When the last command has an input value larger than the data its operating on it would crash. Added a check to ensure there are enough elements to take.
This commit is contained in:
parent
348d75112f
commit
093b9c1c5b
@ -38,11 +38,14 @@ fn last(
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let stream = async_stream! {
|
||||
let v: Vec<_> = context.input.into_vec().await;
|
||||
let k = v.len() - (*amount as usize);
|
||||
let count = (*amount as usize);
|
||||
if count < v.len() {
|
||||
let k = v.len() - count;
|
||||
for x in v[k..].iter() {
|
||||
let y: Tagged<Value> = x.clone();
|
||||
yield ReturnSuccess::value(y)
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok(stream.to_output_stream())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user