From bcf56114fa7f037cea579cdc8d17ac1a5dab93a3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 10 Apr 2018 14:40:23 +0200 Subject: [PATCH] hush: fix eval 'echo ok\' function old new delta parse_stream 2762 2753 -9 Signed-off-by: Denys Vlasenko --- shell/hush.c | 14 +++++++++----- shell/hush_test/hush-parsing/bkslash_eof1.right | 1 + shell/hush_test/hush-parsing/bkslash_eof1.tests | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 shell/hush_test/hush-parsing/bkslash_eof1.right create mode 100755 shell/hush_test/hush-parsing/bkslash_eof1.tests diff --git a/shell/hush.c b/shell/hush.c index 6cd85cc4d..5df8d4744 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -5379,15 +5379,19 @@ static struct pipe *parse_stream(char **pstring, continue; /* get next char */ case '\\': /*nommu_addchr(&ctx.as_string, '\\'); - already done */ - o_addchr(&ctx.word, '\\'); ch = i_getch(input); if (ch == EOF) { -//TODO: in ". FILE" containing "cmd\" (no newline) bash ignores last "\" - syntax_error("\\"); - xfunc_die(); + /* Ignore this '\'. Testcase: eval 'echo Ok\' */ +#if !BB_MMU + /* Remove trailing '\' from ctx.as_string */ + ctx.as_string.data[--ctx.as_string.length] = '\0'; +#endif + continue; /* get next char */ } + o_addchr(&ctx.word, '\\'); /* Example: echo Hello \2>file - * we need to know that word 2 is quoted */ + * we need to know that word 2 is quoted + */ ctx.word.has_quoted_part = 1; nommu_addchr(&ctx.as_string, ch); o_addchr(&ctx.word, ch); diff --git a/shell/hush_test/hush-parsing/bkslash_eof1.right b/shell/hush_test/hush-parsing/bkslash_eof1.right new file mode 100644 index 000000000..9766475a4 --- /dev/null +++ b/shell/hush_test/hush-parsing/bkslash_eof1.right @@ -0,0 +1 @@ +ok diff --git a/shell/hush_test/hush-parsing/bkslash_eof1.tests b/shell/hush_test/hush-parsing/bkslash_eof1.tests new file mode 100755 index 000000000..97629cb13 --- /dev/null +++ b/shell/hush_test/hush-parsing/bkslash_eof1.tests @@ -0,0 +1 @@ +eval 'echo ok\' -- 2.25.1