diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 8ba3872f5..79baf72c9 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -235,6 +235,7 @@ pub fn uu_app<'a>() -> App<'a> { character) is given, it is appended to the line number to separate it from whatever follows. The default for char is a . Line numbers longer than width columns are truncated.") .takes_value(true) + .allow_hyphen_values(true) .value_name("[char][width]") ) .arg( @@ -453,7 +454,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { /// * `args` - Command line arguments fn recreate_arguments(args: &[String]) -> Vec { let column_page_option = Regex::new(r"^[-+]\d+.*").unwrap(); - let num_regex = Regex::new(r"(.\d+)|(\d+)|^[^-]$").unwrap(); + let num_regex = Regex::new(r"^[^-]\d*$").unwrap(); //let a_file: Regex = Regex::new(r"^[^-+].*").unwrap(); let n_regex = Regex::new(r"^-n\s*$").unwrap(); let mut arguments = args.to_owned(); diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs index 5c16e7acc..2e72aaed7 100644 --- a/tests/by-util/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -448,3 +448,16 @@ fn test_with_join_lines_option() { &valid_last_modified_template_vars(start), ); } + +#[test] +fn test_value_for_number_lines() { + // *5 is of the form [SEP[NUMBER]] so is accepted and succeeds + new_ucmd!().args(&["-n", "*5", "test.log"]).succeeds(); + + // a is of the form [SEP[NUMBER]] so is accepted and succeeds + new_ucmd!().args(&["-n", "a", "test.log"]).succeeds(); + + // foo5.txt is of not the form [SEP[NUMBER]] so is not used as value. + // Therefore, pr tries to access the file, which does not exist. + new_ucmd!().args(&["-n", "foo5.txt", "test.log"]).fails(); +}