mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 16:33:37 +01:00
Fixed panic on math with large durations (#3669)
* Output error when ls into a file without permission * math sqrt * added test to check fails when ls into prohibited dir * fix lint * math sqrt with tests and doc * trigger wasm build * Update filesystem_shell.rs * Fix Running echo .. starts printing integers forever * Fixed panic on operations with very large durations Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
This commit is contained in:
parent
55cab9eb4f
commit
2b021472d6
@ -235,6 +235,18 @@ fn duration_math_with_negative() {
|
||||
assert_eq!(actual.out, "-6day");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duration_math_shell_error_on_big_numbers() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
(date now) + 100000000000000day
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Duration overflow"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compound_comparison() {
|
||||
let actual = nu!(
|
||||
|
@ -289,7 +289,17 @@ impl Primitive {
|
||||
.expect("Internal error: conversion from u32 failed"),
|
||||
);
|
||||
let secs = match secs.to_i64() {
|
||||
Some(secs) => secs,
|
||||
//The duration crate doesnt accept seconds bigger than i64::MAX / 1000
|
||||
Some(secs) => match secs.checked_mul(1000) {
|
||||
Some(_) => secs,
|
||||
None => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Internal duration conversion overflow.",
|
||||
"duration overflow",
|
||||
span,
|
||||
))
|
||||
}
|
||||
},
|
||||
None => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Internal duration conversion overflow.",
|
||||
|
Loading…
Reference in New Issue
Block a user