diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-02 13:29:20 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-02 13:29:20 +0200 |
commit | c4c2012284c3a3a45843e9400379c84855d853ef (patch) | |
tree | 113aef7b5e6ac339a919faec68c935d679a74b02 | |
parent | 8b536eb40d7b4e65e3a0223ada7246f538ac6e98 (diff) | |
download | busybox-w32-c4c2012284c3a3a45843e9400379c84855d853ef.tar.gz busybox-w32-c4c2012284c3a3a45843e9400379c84855d853ef.tar.bz2 busybox-w32-c4c2012284c3a3a45843e9400379c84855d853ef.zip |
ash: parser: Fix single-quoted patterns in here-documents
Upstream commit:
From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Fri, 9 Mar 2018 23:07:53 +0800
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>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 2 | ||||
-rw-r--r-- | shell/ash_test/ash-heredoc/heredoc_var_expand1.right | 4 | ||||
-rwxr-xr-x | shell/ash_test/ash-heredoc/heredoc_var_expand1.tests | 11 |
3 files changed, 16 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c index 97379cd92..70a278f42 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -12005,7 +12005,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) | |||
12005 | } | 12005 | } |
12006 | } | 12006 | } |
12007 | #endif | 12007 | #endif |
12008 | if (eofmark == NULL || synstack->dblquote) | 12008 | if (!eofmark || synstack->dblquote || synstack->varnest) |
12009 | USTPUTC(CTLESC, out); | 12009 | USTPUTC(CTLESC, out); |
12010 | USTPUTC(c, out); | 12010 | USTPUTC(c, out); |
12011 | break; | 12011 | break; |
diff --git a/shell/ash_test/ash-heredoc/heredoc_var_expand1.right b/shell/ash_test/ash-heredoc/heredoc_var_expand1.right new file mode 100644 index 000000000..eb221832d --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc_var_expand1.right | |||
@@ -0,0 +1,4 @@ | |||
1 | |||
2 | Ok1:0 | ||
3 | |||
4 | Ok2:0 | ||
diff --git a/shell/ash_test/ash-heredoc/heredoc_var_expand1.tests b/shell/ash_test/ash-heredoc/heredoc_var_expand1.tests new file mode 100755 index 000000000..3b00bab7b --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc_var_expand1.tests | |||
@@ -0,0 +1,11 @@ | |||
1 | x='*' | ||
2 | |||
3 | cat <<- EOF | ||
4 | ${x#'*'} | ||
5 | EOF | ||
6 | echo Ok1:$? | ||
7 | |||
8 | cat <<EOF | ||
9 | ${x#'*'} | ||
10 | EOF | ||
11 | echo Ok2:$? | ||