diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-09-30 00:00:43 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-09-30 00:00:43 +0200 |
commit | bd202a5ec15b82ba9562cdd81157e703349d8459 (patch) | |
tree | 6ecc199048004f741144bbbf9c5b3561f6161d57 | |
parent | d4dd48f2948b006f4ccb7cc2b603fb3d00f90685 (diff) | |
download | busybox-w32-bd202a5ec15b82ba9562cdd81157e703349d8459.tar.gz busybox-w32-bd202a5ec15b82ba9562cdd81157e703349d8459.tar.bz2 busybox-w32-bd202a5ec15b82ba9562cdd81157e703349d8459.zip |
xargs: fix -I SUBSTR behaviour
function old new delta
process_stdin_with_replace 165 204 +39
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | findutils/xargs.c | 21 | ||||
-rwxr-xr-x | testsuite/xargs.tests | 8 |
2 files changed, 24 insertions, 5 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c index ff04bfe7c..e2b3527f3 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -80,9 +80,11 @@ | |||
80 | /* This is a NOEXEC applet. Be very careful! */ | 80 | /* This is a NOEXEC applet. Be very careful! */ |
81 | 81 | ||
82 | 82 | ||
83 | //#define dbg_msg(...) bb_error_msg(__VA_ARGS__) | 83 | #if 0 |
84 | #define dbg_msg(...) ((void)0) | 84 | # define dbg_msg(...) bb_error_msg(__VA_ARGS__) |
85 | 85 | #else | |
86 | # define dbg_msg(...) ((void)0) | ||
87 | #endif | ||
86 | 88 | ||
87 | #ifdef TEST | 89 | #ifdef TEST |
88 | # ifndef ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION | 90 | # ifndef ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION |
@@ -466,9 +468,18 @@ static char* FAST_FUNC process_stdin_with_replace(int n_max_chars, int n_max_arg | |||
466 | 468 | ||
467 | while (1) { | 469 | while (1) { |
468 | int c = getchar(); | 470 | int c = getchar(); |
471 | if (p == buf) { | ||
472 | if (c == EOF) | ||
473 | goto ret; /* last line is empty, return "" */ | ||
474 | if (c == G.eol_ch) | ||
475 | continue; /* empty line, ignore */ | ||
476 | /* Skip leading whitespace of each line: try | ||
477 | * echo -e ' \t\v1 2 3 ' | xargs -I% echo '[%]' | ||
478 | */ | ||
479 | if (ISSPACE(c)) | ||
480 | continue; | ||
481 | } | ||
469 | if (c == EOF || c == G.eol_ch) { | 482 | if (c == EOF || c == G.eol_ch) { |
470 | if (p == buf) | ||
471 | goto ret; /* empty line */ | ||
472 | c = '\0'; | 483 | c = '\0'; |
473 | } | 484 | } |
474 | *p++ = c; | 485 | *p++ = c; |
diff --git a/testsuite/xargs.tests b/testsuite/xargs.tests index 159f1ff69..e7c7c4b3d 100755 --- a/testsuite/xargs.tests +++ b/testsuite/xargs.tests | |||
@@ -61,4 +61,12 @@ testing "xargs -n2" \ | |||
61 | 61 | ||
62 | SKIP= | 62 | SKIP= |
63 | 63 | ||
64 | optional FEATURE_XARGS_SUPPORT_QUOTES | ||
65 | testing "xargs -I skips empty lines and leading whitespace" \ | ||
66 | "xargs -I% echo '[%]'" \ | ||
67 | "[2]\n[4]\n[6 6 ]\n[7]\n" \ | ||
68 | "" " \n2\n\n4\n\n 6 6 \n \v \t 7\n\t\n\v\n" | ||
69 | |||
70 | SKIP= | ||
71 | |||
64 | exit $FAILCOUNT | 72 | exit $FAILCOUNT |