From 65f47be5ee260f8a0ce7747239a7fde8ccb59a83 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Fri, 18 Jun 2021 12:10:40 +0200 Subject: [PATCH] cut: fix `-d=` (#2424) --- src/uu/cut/src/cut.rs | 11 ++++++++++- tests/by-util/test_cut.rs | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index af4a27d8a0e..6602b1eb1b8 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -531,7 +531,16 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let zero_terminated = matches.is_present(options::ZERO_TERMINATED); match matches.value_of(options::DELIMITER) { - Some(delim) => { + Some(mut delim) => { + // GNU's `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 + // Since clap parsing handles `-d=` as delimiter explicitly set to "" and + // an empty delimiter is not accepted by GNU's `cut` (and makes no sense), + // we can use this as basis for a simple workaround: + if delim.is_empty() { + delim = "="; + } if delim.chars().count() > 1 { Err(msg_opt_invalid_should_be!( "empty or 1 character long", diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index 8f81b94c1d5..e21010ec83f 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -157,3 +157,12 @@ fn test_directory_and_no_such_file() { .run() .stderr_is("cut: some: No such file or directory\n"); } + +#[test] +fn test_equal_as_delimiter() { + new_ucmd!() + .args(&["-f", "2", "-d="]) + .pipe_in("--libdir=./out/lib") + .succeeds() + .stdout_only("./out/lib\n"); +}