diff --git a/crates/nu-command/src/filters/drop/column.rs b/crates/nu-command/src/filters/drop/column.rs index 83f2b621e4..6d917d50de 100644 --- a/crates/nu-command/src/filters/drop/column.rs +++ b/crates/nu-command/src/filters/drop/column.rs @@ -49,6 +49,13 @@ impl Command for DropColumn { 1 }; + // Make columns to drop is positive + if columns_to_drop < 0 { + if let Some(expr) = call.positional_nth(0) { + return Err(ShellError::NeedsPositiveValue(expr.span)); + } + } + dropcol(engine_state, span, input, columns_to_drop) } diff --git a/crates/nu-command/tests/commands/drop.rs b/crates/nu-command/tests/commands/drop.rs index 06d2668420..7a02eb09ca 100644 --- a/crates/nu-command/tests/commands/drop.rs +++ b/crates/nu-command/tests/commands/drop.rs @@ -16,6 +16,17 @@ fn columns() { assert_eq!(actual.out, "1"); } +#[test] +fn drop_columns_positive_value() { + let actual = nu!( + cwd: ".", pipeline(r#" + echo [[a, b];[1,2]] | drop column -1 + "#) + ); + + assert!(actual.err.contains("use a positive value")); +} + #[test] fn more_columns_than_table_has() { let actual = nu!(