hush: fix handling of \<eof> in double-quoted strings
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 10 Apr 2018 12:49:01 +0000 (14:49 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 10 Apr 2018 12:49:01 +0000 (14:49 +0200)
function                                             old     new   delta
encode_string                                        268     250     -18

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

index 5df8d4744523cf2cd53e0b55709e839a5e96adc6..98ba96e0c290f3e5c203f497a580e3b8fb853a9f 100644 (file)
@@ -4913,11 +4913,12 @@ static int encode_string(o_string *as_string,
                        ch, ch, !!(dest->o_expflags & EXP_FLAG_ESC_GLOB_CHARS));
        if (process_bkslash && ch == '\\') {
                if (next == EOF) {
-// TODO: what if in interactive shell a file with
-//  echo "unterminated string\<eof>
-// is sourced?
-                       syntax_error("\\<eof>");
-                       xfunc_die();
+                       /* Testcase: in interactive shell a file with
+                        *  echo "unterminated string\<eof>
+                        * is sourced.
+                        */
+                       syntax_error_unterm_ch('"');
+                       return 0; /* error */
                }
                /* bash:
                 * "The backslash retains its special meaning [in "..."]
diff --git a/shell/hush_test/hush-parsing/bkslash_eof2.right b/shell/hush_test/hush-parsing/bkslash_eof2.right
new file mode 100644 (file)
index 0000000..8be7572
--- /dev/null
@@ -0,0 +1,2 @@
+hush: syntax error: unterminated "
+One:1
diff --git a/shell/hush_test/hush-parsing/bkslash_eof2.tests b/shell/hush_test/hush-parsing/bkslash_eof2.tests
new file mode 100755 (executable)
index 0000000..da1f08d
--- /dev/null
@@ -0,0 +1,4 @@
+printf 'echo "unterminated string\\' >test.tmp.sh
+. ./test.tmp.sh
+echo One:$?
+rm -f test.tmp.sh