summary refs log tree commit diff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-09-26 17:14:16 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2007-09-26 17:14:16 +0800
commit5025e10a003d5ce73d845e89a1638a626ab52fa4 (patch)
treecedb134fdcc43c93be2f48bfdf09b4b98960b019
parent[EXPAND] Refresh stack pointers after makestrspace in _rmescapes (diff)
downloaddash-5025e10a003d5ce73d845e89a1638a626ab52fa4.tar.gz
dash-5025e10a003d5ce73d845e89a1638a626ab52fa4.zip
[PARSER] Recognise here-doc delimiters terminated by EOF
Previously dash required a <newline> character to be present in order for
a here-document delimiter to be detected.  Allowing EOF in the absence of
a <newline> to play the same purpose allows some intuitive scripts to
succeed.  POSIX seems to be silence on this so this should be OK.

Test case:

	eval 'cat <<- NOT
		test
	NOT'
	echo OK

Old result:

	test
	NOTOK

New result:

	test
	OK
-rw-r--r--ChangeLog4
-rw-r--r--src/parser.c10
2 files changed, 12 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 670682b..cf56c9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-09-26  Herbert Xu <herbert@gondor.apana.org.au>
+
+	* Recognise here-doc delimiters terminated by EOF.
+
 2007-09-26  Roy Marples <uberlord@gentoo.org>
 
 	* Refresh stack pointers after makestrspace in _rmescapes.
diff --git a/src/parser.c b/src/parser.c
index 1a483d4..cac0aa5 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1049,8 +1049,14 @@ checkend: {
 				char *p, *q;
 
 				p = line;
-				for (q = eofmark + 1 ; *q && *p == *q ; p++, q++);
-				if (*p == '\n' && *q == '\0') {
+				for (q = eofmark + 1;; p++, q++) {
+					c = *p;
+					if (c == '\n')
+						c = 0;
+					if (!*q || c != *q)
+						break;
+				}
+				if (c == *q) {
 					c = PEOF;
 					plinno++;
 					needprompt = doprompt;