aboutsummaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorColin McAllister <colinmca242@gmail.com>2024-07-17 16:33:35 -0500
committerDenys Vlasenko <vda.linux@googlemail.com>2024-12-10 01:27:04 +0100
commit50e2b59370542097eb0efd79cc8d3d39ee52bf82 (patch)
tree83cf691b3f1a0085bd70bf89f8dcd385aeffe911 /testsuite
parent87e60dcf0f7ef917b73353d8605188a420bd91f9 (diff)
downloadbusybox-w32-50e2b59370542097eb0efd79cc8d3d39ee52bf82.tar.gz
busybox-w32-50e2b59370542097eb0efd79cc8d3d39ee52bf82.tar.bz2
busybox-w32-50e2b59370542097eb0efd79cc8d3d39ee52bf82.zip
cut: fix "-s" flag to omit blank lines
Using cut with the delimiter flag ("-d") with the "-s" flag to only output lines containing the delimiter will print blank lines. This is deviant behavior from cut provided by GNU Coreutils. Blank lines should be omitted if "-s" is used with "-d". This change introduces a somewhat naiive, yet efficient solution, where line length is checked before looping though bytes. If line length is zero and the "-s" flag is used, the code will jump to parsing the next line to avoid printing a newline character. function old new delta cut_main 1196 1185 -11 Signed-off-by: Colin McAllister <colinmca242@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'testsuite')
-rwxr-xr-xtestsuite/cut.tests9
1 files changed, 9 insertions, 0 deletions
diff --git a/testsuite/cut.tests b/testsuite/cut.tests
index 2458c019c..0b401bc00 100755
--- a/testsuite/cut.tests
+++ b/testsuite/cut.tests
@@ -65,6 +65,15 @@ testing "cut with -d -f( ) -s" "cut -d' ' -f3 -s input && echo yes" "yes\n" "$in
65testing "cut with -d -f(a) -s" "cut -da -f3 -s input" "n\nsium:Jim\n\ncion:Ed\n" "$input" "" 65testing "cut with -d -f(a) -s" "cut -da -f3 -s input" "n\nsium:Jim\n\ncion:Ed\n" "$input" ""
66testing "cut with -d -f(a) -s -n" "cut -da -f3 -s -n input" "n\nsium:Jim\n\ncion:Ed\n" "$input" "" 66testing "cut with -d -f(a) -s -n" "cut -da -f3 -s -n input" "n\nsium:Jim\n\ncion:Ed\n" "$input" ""
67 67
68input="\
69
70foo bar baz
71
72bing bong boop
73
74"
75testing "cut with -d -s omits blank lines" "cut -d' ' -f2 -s input" "bar\nbong\n" "$input" ""
76
68# substitute for awk 77# substitute for awk
69optional FEATURE_CUT_REGEX 78optional FEATURE_CUT_REGEX
70testing "cut -DF" "cut -DF 2,7,5" \ 79testing "cut -DF" "cut -DF 2,7,5" \