diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index f45fa0cd6e4..ae19b133f70 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1932,8 +1932,10 @@ fn sort_entries(entries: &mut [PathData], config: &Config, out: &mut BufWriter entries.sort_by_key(|k| Reverse(k.md(out).map(|md| md.len()).unwrap_or(0))), // The default sort in GNU ls is case insensitive Sort::Name => entries.sort_by(|a, b| a.display_name.cmp(&b.display_name)), - Sort::Version => entries - .sort_by(|a, b| version_cmp(&a.p_buf.to_string_lossy(), &b.p_buf.to_string_lossy())), + Sort::Version => entries.sort_by(|a, b| { + version_cmp(&a.p_buf.to_string_lossy(), &b.p_buf.to_string_lossy()) + .then(a.p_buf.to_string_lossy().cmp(&b.p_buf.to_string_lossy())) + }), Sort::Extension => entries.sort_by(|a, b| { a.p_buf .extension() diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index a6835f279d3..2eef6912162 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -2311,15 +2311,56 @@ fn test_ls_version_sort() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; for filename in [ - "a2", "b1", "b20", "a1.4", "b3", "b11", "b20b", "b20a", "a100", "a1.13", "aa", "a1", "aaa", - "abab", "ab", "a01.40", "a001.001", + "a2", + "b1", + "b20", + "a1.4", + "a1.40", + "b3", + "b11", + "b20b", + "b20a", + "a100", + "a1.13", + "aa", + "a1", + "aaa", + "a1.00000040", + "abab", + "ab", + "a01.40", + "a001.001", + "a01.0000001", + "a01.001", + "a001.01", ] { at.touch(filename); } let mut expected = vec![ - "a1", "a001.001", "a1.4", "a1.13", "a01.40", "a2", "a100", "aa", "aaa", "ab", "abab", "b1", - "b3", "b11", "b20", "b20a", "b20b", "", // because of '\n' at the end of the output + "a1", + "a001.001", + "a001.01", + "a01.0000001", + "a01.001", + "a1.4", + "a1.13", + "a01.40", + "a1.00000040", + "a1.40", + "a2", + "a100", + "aa", + "aaa", + "ab", + "abab", + "b1", + "b3", + "b11", + "b20", + "b20a", + "b20b", + "", // because of '\n' at the end of the output ]; let result = scene.ucmd().arg("-1v").succeeds();