Skip to content

Commit a560661

Browse files
committed
ls: ignore invalid block size from env vars
1 parent 52af36d commit a560661

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/uu/ls/src/ls.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,14 @@ impl Config {
840840
match parse_size_u64(&raw_block_size.to_string_lossy()) {
841841
Ok(size) => Some(size),
842842
Err(_) => {
843-
return Err(Box::new(LsError::BlockSizeParseError(
844-
opt_block_size.unwrap().clone(),
845-
)));
843+
// only fail if invalid block size was specified with --block-size,
844+
// ignore invalid block size from env vars
845+
if let Some(invalid_block_size) = opt_block_size {
846+
return Err(Box::new(LsError::BlockSizeParseError(
847+
invalid_block_size.clone(),
848+
)));
849+
}
850+
None
846851
}
847852
}
848853
} else if env_var_posixly_correct.is_some() {

tests/by-util/test_ls.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3874,6 +3874,14 @@ fn test_ls_invalid_block_size() {
38743874
.stderr_is("ls: invalid --block-size argument 'invalid'\n");
38753875
}
38763876

3877+
// TODO ensure the correct block size is used when using -l because
3878+
// the output of "ls -l" and "BLOCK_SIZE=invalid ls -l" is different
3879+
#[test]
3880+
fn test_ls_invalid_block_size_in_env_var() {
3881+
new_ucmd!().env("LS_BLOCK_SIZE", "invalid").succeeds();
3882+
new_ucmd!().env("BLOCK_SIZE", "invalid").succeeds();
3883+
}
3884+
38773885
#[cfg(all(unix, feature = "dd"))]
38783886
#[test]
38793887
fn test_ls_block_size_override() {

0 commit comments

Comments
 (0)