mirror of
https://github.com/nushell/nushell.git
synced 2024-11-26 10:23:52 +01:00
Error on negative argument of first
(#7186)
Fixes a two's complement underflow/overflow when given a negative arg. Breaking change as it is throwing an error instead of most likely returning most of the output. Same behavior as #7184 # Tests + Formatting + 1 failure test # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
parent
ce03d8eb12
commit
cf96677c78
@ -97,6 +97,7 @@ fn first_helper(
|
|||||||
// the first N elements is covered by `take`
|
// the first N elements is covered by `take`
|
||||||
let return_single_element = rows.is_none();
|
let return_single_element = rows.is_none();
|
||||||
let rows_desired: usize = match rows {
|
let rows_desired: usize = match rows {
|
||||||
|
Some(i) if i < 0 => return Err(ShellError::NeedsPositiveValue(head)),
|
||||||
Some(x) => x as usize,
|
Some(x) => x as usize,
|
||||||
None => 1,
|
None => 1,
|
||||||
};
|
};
|
||||||
|
@ -92,3 +92,16 @@ fn works_with_binary_list() {
|
|||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn errors_on_negative_rows() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: ".", pipeline(
|
||||||
|
r#"
|
||||||
|
[1, 2, 3]
|
||||||
|
| first -10
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert!(actual.err.contains("use a positive value"));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user