diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 2ebd2fb973d..30255b4422f 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -569,10 +569,20 @@ impl Config { }; let width = match options.value_of(options::WIDTH) { - Some(x) => match x.parse::() { - Ok(u) => u, - Err(_) => return Err(LsError::InvalidLineWidth(x.into()).into()), - }, + Some(x) => { + if x.starts_with('0') && x.len() > 1 { + // Read number as octal + match u16::from_str_radix(x, 8) { + Ok(v) => v, + Err(_) => return Err(LsError::InvalidLineWidth(x.into()).into()), + } + } else { + match x.parse::() { + Ok(u) => u, + Err(_) => return Err(LsError::InvalidLineWidth(x.into()).into()), + } + } + } None => match termsize::get() { Some(size) => size.cols, None => match std::env::var_os("COLUMNS") { diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index db2c3d445f2..739fe8b4893 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -650,6 +650,21 @@ fn test_ls_width() { .stdout_only("test-width-1 test-width-2 test-width-3 test-width-4\n"); } + for option in [ + "-w 062", + "-w=062", + "--width=062", + "--width 062", + "--wid=062", + ] { + scene + .ucmd() + .args(&option.split(' ').collect::>()) + .arg("-C") + .succeeds() + .stdout_only("test-width-1 test-width-3\ntest-width-2 test-width-4\n"); + } + scene .ucmd() .arg("-w=bad")