diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 209745ade..ec7fab4e9 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -966,7 +966,12 @@ impl Config { let mut quoting_style = extract_quoting_style(options, show_control); let indicator_style = extract_indicator_style(options); - let time_style = parse_time_style(options)?; + // Only parse the value to "--time-style" if it will become relevant. + let time_style = if format == Format::Long { + parse_time_style(options)? + } else { + TimeStyle::Iso + }; let mut ignore_patterns: Vec = Vec::new(); diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index efe9e1056..2f48e4460 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -86,6 +86,31 @@ fn test_invalid_value_returns_2() { } } +#[test] +fn test_invalid_value_time_style() { + // This is the only flag which does not raise an error if it is invalid but not actually used: + new_ucmd!() + .arg("--time-style=definitely_invalid_value") + .succeeds() + .no_stderr() + .code_is(0); + // If it is used, error: + new_ucmd!() + .arg("-g") + .arg("--time-style=definitely_invalid_value") + .fails() + .no_stdout() + .code_is(2); + // If it only looks temporarily like it might be used, no error: + new_ucmd!() + .arg("-l") + .arg("--time-style=definitely_invalid_value") + .arg("--format=single-column") + .succeeds() + .no_stderr() + .code_is(0); +} + #[test] fn test_ls_ls() { new_ucmd!().succeeds();