diff --git a/crates/nu-parser/src/parse.rs b/crates/nu-parser/src/parse.rs index b350b877ea..fbb1094eab 100644 --- a/crates/nu-parser/src/parse.rs +++ b/crates/nu-parser/src/parse.rs @@ -227,6 +227,15 @@ fn parse_range( ); }; + if lite_arg.item[0..dotdot_pos].is_empty() + && lite_arg.item[(dotdot_pos + operator_str.len())..].is_empty() + { + return ( + garbage(lite_arg.span), + Some(ParseError::mismatch("range", lite_arg.clone())), + ); + } + let numbers: Vec<_> = lite_arg.item.split(operator_str).collect(); if numbers.len() != 2 { diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 936b734f67..dda36b065a 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -433,6 +433,30 @@ fn index_cell_alt() { assert_eq!(actual.out, "bob"); } +#[test] +fn not_echoing_ranges_without_numbers() { + let actual = nu!( + cwd: ".", + r#" + echo .. + "# + ); + + assert_eq!(actual.out, ".."); +} + +#[test] +fn not_echoing_exclusive_ranges_without_numbers() { + let actual = nu!( + cwd: ".", + r#" + echo ..< + "# + ); + + assert_eq!(actual.out, "..<"); +} + #[test] fn echoing_ranges() { let actual = nu!(