From 8693eaa3b983595943b6dafb18aff630298dbd04 Mon Sep 17 00:00:00 2001 From: anastygnome Date: Sat, 11 Jun 2022 08:41:08 +0200 Subject: [PATCH 1/2] Remove unnecessary trailing space when using the comma format (-m) unnecessary trailing space was being added. because we were padding for alignment, which is not required with -m fixes #3608 Signed-off-by: anastygnome --- src/uu/ls/src/ls.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 30255b442..0fa748324 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1874,7 +1874,12 @@ fn display_additional_leading_info( } else { "?".to_owned() }; - write!(result, "{} ", pad_left(&s, padding.block_size)).unwrap(); + // extra space is insert to align the sizes, as needed for all formats, except for the comma format. + if config.format == Format::Commas { + write!(result, "{} ", s).unwrap(); + } else { + write!(result, "{} ", pad_left(&s, padding.block_size)).unwrap(); + }; } Ok(result) } From 0ef67326323d5bae1c3ab78a8b40dbf3815df695 Mon Sep 17 00:00:00 2001 From: anastygnome Date: Mon, 13 Jun 2022 11:29:13 +0200 Subject: [PATCH 2/2] Add a test like the one in the issue. Signed-off-by: anastygnome --- tests/by-util/test_ls.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 739fe8b48..c0d54a7cd 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -803,6 +803,30 @@ fn test_ls_commas() { } } +#[test] +fn test_ls_commas_trailing() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.touch(&at.plus_as_string("test-commas-trailing-2")); + + at.touch(&at.plus_as_string("test-commas-trailing-1")); + at.append( + "test-commas-trailing-1", + &(0..2000) + .map(|x| x.to_string()) + .collect::>() + .join("\n"), + ); + + scene + .ucmd() + .arg("-sm") + .arg("./test-commas-trailing-1") + .arg("./test-commas-trailing-2") + .succeeds() + .stdout_matches(&Regex::new(r"\S$").unwrap()); // matches if there is no whitespace at the end of stdout. +} + #[test] fn test_ls_long() { let scene = TestScenario::new(util_name!());