From e8d78e4e92f5aa266bca70890462b9f29337b3c6 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] cut: don't rewrite a -d= file operand after -- A file operand named `-d=` after `--` was rewritten to `--delimiter==` before clap parsing, so cut opened the wrong file. Stop the rewrite once `--` has been seen. Fixes #15806 --- src/uu/cut/src/cut.rs | 9 ++++++++- tests/by-util/test_cut.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 9680ece4a02..283ce9beee2 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -1047,8 +1047,15 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // GNU `cut` supports `-d=` to set the delimiter to `=`. // Clap parsing is limited in this situation, see: // https://github.com/uutils/coreutils/issues/2424#issuecomment-863825242 + // Arguments after `--` are file operands and must be left untouched. + let mut seen_double_dash = false; let args = args.into_iter().map(|x| { - if x == "-d=" { + if seen_double_dash { + x + } else if x == "--" { + seen_double_dash = true; + x + } else if x == "-d=" { "--delimiter==".into() } else { x diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index 294863baa73..21d28924d1d 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -367,6 +367,18 @@ fn test_equal_as_delimiter() { } } +#[test] +fn test_equal_delimiter_file_operand_after_double_dash() { + // After `--`, a file named `-d=` is an operand and must not be rewritten + // to `--delimiter==`. #15806 + let (at, mut ucmd) = at_and_ucmd!(); + at.write("-d=", "a:b:c\n"); + at.write("--delimiter==", "x:y:z\n"); + ucmd.args(&["-d:", "-f2", "--", "-d="]) + .succeeds() + .stdout_only("b\n"); +} + #[test] fn test_empty_string_as_delimiter() { new_ucmd!()