From 8b36ee182616019349652b493a9739f17d0231f0 Mon Sep 17 00:00:00 2001 From: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com> Date: Sun, 25 Oct 2026 18:53:27 +0530 Subject: [PATCH] sort: don't rewrite a -t file operand after -- The `-t` to `--field-separator=` rewrite ran on every argument, including file operands after `--`, so `sort -- -t=` tried to use `=` as a separator instead of reading the file `-t=`. Stop the rewrite once `--` has been seen, as in cut (#15806). --- src/uu/sort/src/sort.rs | 9 +++++++++ tests/by-util/test_sort.rs | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 34a5bd6118..b8d8b10d03 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -2155,7 +2155,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // https://github.com/uutils/coreutils/issues/2424#issuecomment-863825242, // and the same rewrite in `cut`), so rewrite every attached `-t` // argument to its long form, which preserves the separator verbatim. + // Arguments after `--` are file operands and must be left untouched. + let mut seen_double_dash = false; let args = args.into_iter().map(|x| { + if seen_double_dash { + return x; + } + if x == "--" { + seen_double_dash = true; + return x; + } // Non-UTF-8 separators are rejected later anyway, so lossy conversion // here only affects arguments that cannot become a valid separator. let as_str = x.to_string_lossy(); diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index c309ad5b29..173938304b 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -2097,6 +2097,15 @@ fn test_separator_attached_equals() { .stdout_only("b=a=d\na=b=c\n"); } +#[test] +fn test_separator_like_file_operand_after_double_dash() { + // After `--`, a file named `-t=` is an operand and must not be rewritten + // to `--field-separator==`. + let (at, mut ucmd) = at_and_ucmd!(); + at.write("-t=", "b\na\n"); + ucmd.args(&["--", "-t="]).succeeds().stdout_only("a\nb\n"); +} + #[test] fn test_separator_attached_equals_double() { // `-t==` selects the two-character separator `==`, which GNU rejects.