summary refs log tree commit diff
path: root/src/parser.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2018-03-09 23:07:53 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2018-03-22 00:29:58 +0800
commit9ee3343965950bad08e97f43c8c376b89a50b099 (patch)
tree8b58e39c7bc29bf6b99f505c2ebe62cbb84090f2 /src/parser.c
parentparser: Add syntax stack for recursive parsing (diff)
downloaddash-9ee3343965950bad08e97f43c8c376b89a50b099.tar.gz
dash-9ee3343965950bad08e97f43c8c376b89a50b099.zip
parser: Fix single-quoted patterns in here-documents
The script

	x=*
	cat <<- EOF
		${x#'*'}
	EOF

prints * instead of nothing as it should.  The problem is that
when we're in sqsyntax context in a here-document, we won't add
CTLESC as we should.  This patch fixes it:

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to '')
-rw-r--r--src/parser.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/parser.c b/src/parser.c
index c28363c..cd98094 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -934,7 +934,8 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs)
 				USTPUTC(c, out);
 				break;
 			case CCTL:
-				if (eofmark == NULL || synstack->dblquote)
+				if ((!eofmark) | synstack->dblquote |
+				    synstack->varnest)
 					USTPUTC(CTLESC, out);
 				USTPUTC(c, out);
 				break;