summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-03-29 12:59:54 +0100
committerRon Yorston <rmy@pobox.com>2020-03-29 12:59:54 +0100
commit5d6744d8635fcbd1ef4cce85a737aacfde4ddeba (patch)
tree027ff579a5b09a095ba0ba03fbc4f8ee1c4c5abc
parentbeff2721928fdb624c227cccd15bde7ae68862e3 (diff)
downloadbusybox-w32-5d6744d8635fcbd1ef4cce85a737aacfde4ddeba.tar.gz
busybox-w32-5d6744d8635fcbd1ef4cce85a737aacfde4ddeba.tar.bz2
busybox-w32-5d6744d8635fcbd1ef4cce85a737aacfde4ddeba.zip
xargs: restore correct behaviour of -n option
Since commit 1ff7002b1 (xargs: fix handling of quoted arguments, closes 11441) the -n option hasn't worked properly: $ echo 1 2 3 | xargs -n 1 echo 1 2 3 $ Because state is now remembered between calls to process_stdin() it's necessary to update the state before any premature return.
-rw-r--r--findutils/xargs.c2
-rwxr-xr-xtestsuite/xargs.tests11
2 files changed, 12 insertions, 1 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c
index 8d3a0027c..71350d470 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -388,6 +388,7 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
388 } 388 }
389 } 389 }
390 if (state == SPACE) { /* word's delimiter or EOF detected */ 390 if (state == SPACE) { /* word's delimiter or EOF detected */
391 state = NORM;
391 if (q) { 392 if (q) {
392 bb_error_msg_and_die("unmatched %s quote", 393 bb_error_msg_and_die("unmatched %s quote",
393 q == '\'' ? "single" : "double"); 394 q == '\'' ? "single" : "double");
@@ -408,7 +409,6 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
408 if (n_max_arg == 0) { 409 if (n_max_arg == 0) {
409 goto ret; 410 goto ret;
410 } 411 }
411 state = NORM;
412 } 412 }
413 if (p == buf) { 413 if (p == buf) {
414 goto ret; 414 goto ret;
diff --git a/testsuite/xargs.tests b/testsuite/xargs.tests
index 855b33bc2..159f1ff69 100755
--- a/testsuite/xargs.tests
+++ b/testsuite/xargs.tests
@@ -48,6 +48,17 @@ testing "xargs argument line too long" \
48 "seq 10000 99999 | sed -e 's/^/\"/' -e 's/$/\"/' | xargs echo | grep -o 99999; echo \$?" \ 48 "seq 10000 99999 | sed -e 's/^/\"/' -e 's/$/\"/' | xargs echo | grep -o 99999; echo \$?" \
49 "99999\n0\n" \ 49 "99999\n0\n" \
50 "" "" 50 "" ""
51
52testing "xargs -n1" \
53 "xargs -n1 echo" \
54 "1\n2\n3\n4\n5\n" \
55 "" "1 2 3 4 5\n"
56
57testing "xargs -n2" \
58 "xargs -n2 echo" \
59 "1 2\n3 4\n5\n" \
60 "" "1 2 3 4 5\n"
61
51SKIP= 62SKIP=
52 63
53exit $FAILCOUNT 64exit $FAILCOUNT