Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/uu/cut/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/by-util/test_cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
Expand Down
Loading