aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-11 01:15:33 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-11 01:15:33 +0200
commit89e9d5534d0e8879803ed9dbb25dff3989c31202 (patch)
treeb1f7c630418dd97e4fad62d114381d0297460d52
parent3632cb15f16a7596a68dccfd66a2ad9496bf9fd9 (diff)
downloadbusybox-w32-89e9d5534d0e8879803ed9dbb25dff3989c31202.tar.gz
busybox-w32-89e9d5534d0e8879803ed9dbb25dff3989c31202.tar.bz2
busybox-w32-89e9d5534d0e8879803ed9dbb25dff3989c31202.zip
hush: do not drop backslash from eval 'echo ok\'
newer bash does not drop it, most other shells too function old new delta unbackslash 39 57 +18 parse_stream 2753 2751 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 18/-2) Total: 16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c2
-rw-r--r--shell/ash_test/ash-parsing/bkslash_eof1.right1
-rwxr-xr-xshell/ash_test/ash-parsing/bkslash_eof1.tests1
-rw-r--r--shell/ash_test/ash-redir/redir_exec1.right2
-rw-r--r--shell/hush.c22
-rw-r--r--shell/hush_test/hush-parsing/bkslash_eof1.right2
6 files changed, 22 insertions, 8 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 713219b6e..6f8bc9042 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -203,7 +203,7 @@
203 * TODO: 203 * TODO:
204 * singleword+noglob expansion: 204 * singleword+noglob expansion:
205 * v='a b'; [[ $v = 'a b' ]]; echo 0:$? 205 * v='a b'; [[ $v = 'a b' ]]; echo 0:$?
206 * [[ /bin/* ]]; echo 0:$? 206 * [[ /bin/n* ]]; echo 0:$?
207 * -a/-o are not AND/OR ops! (they are just strings) 207 * -a/-o are not AND/OR ops! (they are just strings)
208 * quoting needs to be considered (-f is an operator, "-f" and ""-f are not; etc) 208 * quoting needs to be considered (-f is an operator, "-f" and ""-f are not; etc)
209 * = is glob match operator, not equality operator: STR = GLOB 209 * = is glob match operator, not equality operator: STR = GLOB
diff --git a/shell/ash_test/ash-parsing/bkslash_eof1.right b/shell/ash_test/ash-parsing/bkslash_eof1.right
new file mode 100644
index 000000000..6c6df0b0c
--- /dev/null
+++ b/shell/ash_test/ash-parsing/bkslash_eof1.right
@@ -0,0 +1 @@
ok\
diff --git a/shell/ash_test/ash-parsing/bkslash_eof1.tests b/shell/ash_test/ash-parsing/bkslash_eof1.tests
new file mode 100755
index 000000000..97629cb13
--- /dev/null
+++ b/shell/ash_test/ash-parsing/bkslash_eof1.tests
@@ -0,0 +1 @@
eval 'echo ok\'
diff --git a/shell/ash_test/ash-redir/redir_exec1.right b/shell/ash_test/ash-redir/redir_exec1.right
index d4393d10c..c98455bf5 100644
--- a/shell/ash_test/ash-redir/redir_exec1.right
+++ b/shell/ash_test/ash-redir/redir_exec1.right
@@ -1,2 +1,2 @@
1redir_exec1.tests: line 1: can't create /cant/be/created: nonexistent directory 1./redir_exec1.tests: line 1: can't create /cant/be/created: nonexistent directory
2First 2First
diff --git a/shell/hush.c b/shell/hush.c
index 3afb70cb0..523fc1a31 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -83,7 +83,7 @@
83 * Status of [[ support: 83 * Status of [[ support:
84 * [[ args ]] are CMD_SINGLEWORD_NOGLOB: 84 * [[ args ]] are CMD_SINGLEWORD_NOGLOB:
85 * v='a b'; [[ $v = 'a b' ]]; echo 0:$? 85 * v='a b'; [[ $v = 'a b' ]]; echo 0:$?
86 * [[ /bin/* ]]; echo 0:$? 86 * [[ /bin/n* ]]; echo 0:$?
87 * TODO: 87 * TODO:
88 * &&/|| are AND/OR ops, -a/-o are not 88 * &&/|| are AND/OR ops, -a/-o are not
89 * quoting needs to be considered (-f is an operator, "-f" and ""-f are not; etc) 89 * quoting needs to be considered (-f is an operator, "-f" and ""-f are not; etc)
@@ -1426,8 +1426,19 @@ static char *unbackslash(char *src)
1426{ 1426{
1427 char *dst = src = strchrnul(src, '\\'); 1427 char *dst = src = strchrnul(src, '\\');
1428 while (1) { 1428 while (1) {
1429 if (*src == '\\') 1429 if (*src == '\\') {
1430 src++; 1430 src++;
1431 if (*src != '\0') {
1432 /* \x -> x */
1433 *dst++ = *src++;
1434 continue;
1435 }
1436 /* else: "\<nul>". Do not delete this backslash.
1437 * Testcase: eval 'echo ok\'
1438 */
1439 *dst++ = '\\';
1440 /* fallthrough */
1441 }
1431 if ((*dst++ = *src++) == '\0') 1442 if ((*dst++ = *src++) == '\0')
1432 break; 1443 break;
1433 } 1444 }
@@ -5392,16 +5403,17 @@ static struct pipe *parse_stream(char **pstring,
5392 continue; /* get next char */ 5403 continue; /* get next char */
5393 case '\\': 5404 case '\\':
5394 /*nommu_addchr(&ctx.as_string, '\\'); - already done */ 5405 /*nommu_addchr(&ctx.as_string, '\\'); - already done */
5406 o_addchr(&ctx.word, '\\');
5395 ch = i_getch(input); 5407 ch = i_getch(input);
5396 if (ch == EOF) { 5408 if (ch == EOF) {
5397 /* Ignore this '\'. Testcase: eval 'echo Ok\' */ 5409 /* Testcase: eval 'echo Ok\' */
5398#if !BB_MMU 5410
5411#if 0 /* bash-4.3.43 was removing backslash, but 4.4.19 retains it, most other shells too */
5399 /* Remove trailing '\' from ctx.as_string */ 5412 /* Remove trailing '\' from ctx.as_string */
5400 ctx.as_string.data[--ctx.as_string.length] = '\0'; 5413 ctx.as_string.data[--ctx.as_string.length] = '\0';
5401#endif 5414#endif
5402 continue; /* get next char */ 5415 continue; /* get next char */
5403 } 5416 }
5404 o_addchr(&ctx.word, '\\');
5405 /* Example: echo Hello \2>file 5417 /* Example: echo Hello \2>file
5406 * we need to know that word 2 is quoted 5418 * we need to know that word 2 is quoted
5407 */ 5419 */
diff --git a/shell/hush_test/hush-parsing/bkslash_eof1.right b/shell/hush_test/hush-parsing/bkslash_eof1.right
index 9766475a4..6c6df0b0c 100644
--- a/shell/hush_test/hush-parsing/bkslash_eof1.right
+++ b/shell/hush_test/hush-parsing/bkslash_eof1.right
@@ -1 +1 @@
ok ok\