From 808865e4ac4f9289a770dbc20c9e52cedf6aed19 Mon Sep 17 00:00:00 2001 From: Kaua Klassmann <131408936+Kaua-Klassmann@users.noreply.github.com> Date: Thu, 12 Feb 2026 07:52:22 -0300 Subject: [PATCH] fix: scientific notation is incorrectly parsed in general numeric sort (#10437) * fix: scientific notation is incorrectly parsed in general sort * test(sort): refactor exponents_positive_general test --------- Co-authored-by: Sylvestre Ledru --- src/uu/sort/src/sort.rs | 2 +- tests/by-util/test_sort.rs | 11 ++++++++++- .../sort/exponents-positive-general.expected | 12 ------------ tests/fixtures/sort/exponents-positive-general.txt | 12 ------------ 4 files changed, 11 insertions(+), 26 deletions(-) delete mode 100644 tests/fixtures/sort/exponents-positive-general.expected delete mode 100644 tests/fixtures/sort/exponents-positive-general.txt diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 52247c4fe..4ea294ee6 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -2816,7 +2816,7 @@ fn get_leading_gen(inp: &[u8], decimal_pt: u8) -> Range { if let Some(&(_, &next_char)) = char_indices.peek() { if (next_char == b'+' || next_char == b'-') && matches!( - char_indices.peek_nth(2), + char_indices.peek_nth(1), Some((_, c)) if c.is_ascii_digit() ) { diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 42cbcff5a..34a80636f 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -478,10 +478,19 @@ fn test_non_printing_chars() { } #[test] -fn test_exponents_positive_general_fixed() { +fn test_exponents_general() { test_helper("exponents_general", &["-g"]); } +#[test] +fn test_exponents_positive_general() { + new_ucmd!() + .pipe_in("1\n2e3\n1e-5") + .arg("-g") + .succeeds() + .stdout_only("1e-5\n1\n2e3\n"); +} + #[test] fn test_exponents_positive_numeric() { test_helper( diff --git a/tests/fixtures/sort/exponents-positive-general.expected b/tests/fixtures/sort/exponents-positive-general.expected deleted file mode 100644 index 3dbc92fe5..000000000 --- a/tests/fixtures/sort/exponents-positive-general.expected +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - -10E -1000EDKLD -10000K78 -+100000 -100E6 -50e10 diff --git a/tests/fixtures/sort/exponents-positive-general.txt b/tests/fixtures/sort/exponents-positive-general.txt deleted file mode 100644 index 23ea52771..000000000 --- a/tests/fixtures/sort/exponents-positive-general.txt +++ /dev/null @@ -1,12 +0,0 @@ -10000K78 -10E - - -1000EDKLD - - -100E6 - -50e10 -+100000 -