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.