hush: fix eval 'echo ok\'
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 10 Apr 2018 12:40:23 +0000 (14:40 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 10 Apr 2018 12:40:23 +0000 (14:40 +0200)
function                                             old     new   delta
parse_stream                                        2762    2753      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/hush.c
shell/hush_test/hush-parsing/bkslash_eof1.right [new file with mode: 0644]
shell/hush_test/hush-parsing/bkslash_eof1.tests [new file with mode: 0755]

index 6cd85cc4dc4323783f6f5f15f0ee64e9eb9a7054..5df8d4744523cf2cd53e0b55709e839a5e96adc6 100644 (file)
@@ -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("\\<eof>");
-                               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 (file)
index 0000000..9766475
--- /dev/null
@@ -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 (executable)
index 0000000..97629cb
--- /dev/null
@@ -0,0 +1 @@
+eval 'echo ok\'