1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

pr: fix heuristic for number-lines argument (#3109)

This commit is contained in:
Terts Diepraam 2022-02-23 23:12:05 +01:00 committed by Sylvestre Ledru
parent 75b3cbcfd9
commit bb379b5384
2 changed files with 15 additions and 1 deletions

View file

@ -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 character) is given, it is appended to the line number to separate it from whatever follows. The default
for char is a <tab>. Line numbers longer than width columns are truncated.") for char is a <tab>. Line numbers longer than width columns are truncated.")
.takes_value(true) .takes_value(true)
.allow_hyphen_values(true)
.value_name("[char][width]") .value_name("[char][width]")
) )
.arg( .arg(
@ -453,7 +454,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
/// * `args` - Command line arguments /// * `args` - Command line arguments
fn recreate_arguments(args: &[String]) -> Vec<String> { fn recreate_arguments(args: &[String]) -> Vec<String> {
let column_page_option = Regex::new(r"^[-+]\d+.*").unwrap(); 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 a_file: Regex = Regex::new(r"^[^-+].*").unwrap();
let n_regex = Regex::new(r"^-n\s*$").unwrap(); let n_regex = Regex::new(r"^-n\s*$").unwrap();
let mut arguments = args.to_owned(); let mut arguments = args.to_owned();

View file

@ -448,3 +448,16 @@ fn test_with_join_lines_option() {
&valid_last_modified_template_vars(start), &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();
}