aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-09-30 00:00:43 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2020-09-30 00:00:43 +0200
commitbd202a5ec15b82ba9562cdd81157e703349d8459 (patch)
tree6ecc199048004f741144bbbf9c5b3561f6161d57
parentd4dd48f2948b006f4ccb7cc2b603fb3d00f90685 (diff)
downloadbusybox-bd202a5ec15b82ba9562cdd81157e703349d8459.tar.gz
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.c21
-rwxr-xr-xtestsuite/xargs.tests8
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 @@
/* This is a NOEXEC applet. Be very careful! */
-//#define dbg_msg(...) bb_error_msg(__VA_ARGS__)
-#define dbg_msg(...) ((void)0)
-
+#if 0
+# define dbg_msg(...) bb_error_msg(__VA_ARGS__)
+#else
+# define dbg_msg(...) ((void)0)
+#endif
#ifdef TEST
# 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
while (1) {
int c = getchar();
+ if (p == buf) {
+ if (c == EOF)
+ goto ret; /* last line is empty, return "" */
+ if (c == G.eol_ch)
+ continue; /* empty line, ignore */
+ /* Skip leading whitespace of each line: try
+ * echo -e ' \t\v1 2 3 ' | xargs -I% echo '[%]'
+ */
+ if (ISSPACE(c))
+ continue;
+ }
if (c == EOF || c == G.eol_ch) {
- if (p == buf)
- goto ret; /* empty line */
c = '\0';
}
*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" \
SKIP=
+optional FEATURE_XARGS_SUPPORT_QUOTES
+testing "xargs -I skips empty lines and leading whitespace" \
+ "xargs -I% echo '[%]'" \
+ "[2]\n[4]\n[6 6 ]\n[7]\n" \
+ "" " \n2\n\n4\n\n 6 6 \n \v \t 7\n\t\n\v\n"
+
+SKIP=
+
exit $FAILCOUNT