sh: Allow terminating a heredoc with a terminator at EOF w/o newline.
authorPeter Avalos <pavalos@dragonflybsd.org>
Tue, 5 Jul 2011 03:35:34 +0000 (17:35 -1000)
committerPeter Avalos <pavalos@dragonflybsd.org>
Sun, 21 Aug 2011 20:49:07 +0000 (13:49 -0700)
Obtained-from:   FreeBSD SVN rev 222134

bin/sh/parser.c
tools/regression/bin/sh/parser/heredoc11.0 [new file with mode: 0644]

index 6f37eb8..f5ad636 100644 (file)
@@ -34,7 +34,7 @@
  * SUCH DAMAGE.
  *
  * @(#)parser.c        8.7 (Berkeley) 5/16/95
- * $FreeBSD: src/bin/sh/parser.c,v 1.110 2011/05/08 17:40:10 jilles Exp $
+ * $FreeBSD: src/bin/sh/parser.c,v 1.111 2011/05/20 16:03:36 jilles Exp $
  */
 
 #include <stdio.h>
@@ -1512,10 +1512,12 @@ checkend: {
 
                                p = line;
                                for (q = eofmark + 1 ; *q && *p == *q ; p++, q++);
-                               if (*p == '\n' && *q == '\0') {
+                               if ((*p == '\0' || *p == '\n') && *q == '\0') {
                                        c = PEOF;
-                                       plinno++;
-                                       needprompt = doprompt;
+                                       if (*p == '\n') {
+                                               plinno++;
+                                               needprompt = doprompt;
+                                       }
                                } else {
                                        pushstring(line, strlen(line), NULL);
                                }
diff --git a/tools/regression/bin/sh/parser/heredoc11.0 b/tools/regression/bin/sh/parser/heredoc11.0
new file mode 100644 (file)
index 0000000..0b254cf
--- /dev/null
@@ -0,0 +1,26 @@
+# $FreeBSD: src/tools/regression/bin/sh/parser/heredoc11.0,v 1.1 2011/05/20 16:03:36 jilles Exp $
+
+failures=''
+
+check() {
+       if eval "[ $* ]"; then
+               :
+       else
+               echo "Failed: $*"
+               failures=x$failures
+       fi
+}
+
+check '`cat <<EOF
+foo
+EOF` = foo'
+
+check '"`cat <<EOF
+foo
+EOF`" = foo'
+
+check '`eval "cat <<EOF
+foo
+EOF"` = foo'
+
+test "x$failures" = x