From 96a230f17ba6cb1a7ad1e383d595424da02e87fc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 13 Dec 2024 19:31:41 +0100 Subject: cut: fix handling of -d '' Signed-off-by: Denys Vlasenko --- coreutils/cut.c | 2 +- testsuite/cut.tests | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/coreutils/cut.c b/coreutils/cut.c index e12c56732..e33626d7f 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c @@ -309,7 +309,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv) #endif if (!odelim) odelim = (opt & OPT_REGEX) ? " " : delim; - if (!delim || !*delim) + if (!delim) delim = (opt & OPT_REGEX) ? "[[:space:]]+" : "\t"; // argc -= optind; diff --git a/testsuite/cut.tests b/testsuite/cut.tests index 8da390cd7..52d05fde3 100755 --- a/testsuite/cut.tests +++ b/testsuite/cut.tests @@ -142,4 +142,16 @@ testing "cut -dNEWLINE --output-delimiter EMPTY_INPUT" \ "" \ "" "" +# This seems to work as if delimiter is never found. +# We test here that -d '' does *not* operate as if there was no -d +# and delimiter has defaulted to TAB: +testing "cut -d EMPTY" \ + "cut -d '' -f2-" \ + "1 2\t3 4 5\n" \ + "" "1 2\t3 4 5\n" +testing "cut -d EMPTY -s" \ + "cut -d '' -f2- -s" \ + "" \ + "" "1 2\t3 4 5\n" + exit $FAILCOUNT -- cgit v1.2.3-55-g6feb