diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-02-17 10:24:32 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-02-17 10:24:32 +0100 |
commit | 9ee5892798be81f7a6f3e070ecd52cbf0d55740e (patch) | |
tree | 9801edcaadd307687df6f33cad7ba7edd1e2b75b | |
parent | c2ce888030b6b880b3229520a8ff7d7026248a9a (diff) | |
download | busybox-w32-9ee5892798be81f7a6f3e070ecd52cbf0d55740e.tar.gz busybox-w32-9ee5892798be81f7a6f3e070ecd52cbf0d55740e.tar.bz2 busybox-w32-9ee5892798be81f7a6f3e070ecd52cbf0d55740e.zip |
ash: expand: Fix trailing newlines processing in backquote expanding
Upstream commit:
Date: Mon, 29 Apr 2019 19:13:37 +0500
expand: Fix trailing newlines processing in backquote expanding
According to POSIX.1-2008 we should remove newlines only at the end of
the substitution. Newlines-only substitions causes dash to remove
newlines before beggining of the substitution. The following code:
cat <<END
1
$(echo "")
2
END
prints "1<newline>2" instead of expected "1<newline><newline>2".
This patch fixes trailing newlines processing in backquote expanding.
Signed-off-by: Nikolai Merinov <n.merinov@inango-systems.com>
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-psubst/tick_in_heredoc.right | 5 | ||||
-rwxr-xr-x | shell/ash_test/ash-psubst/tick_in_heredoc.tests | 7 | ||||
-rw-r--r-- | shell/hush_test/hush-psubst/tick_in_heredoc.right | 5 | ||||
-rwxr-xr-x | shell/hush_test/hush-psubst/tick_in_heredoc.tests | 7 |
5 files changed, 25 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c index 90496ba7e..dfe6d1c48 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -6578,7 +6578,7 @@ expbackq(union node *cmd, int flag) | |||
6578 | 6578 | ||
6579 | /* Eat all trailing newlines */ | 6579 | /* Eat all trailing newlines */ |
6580 | dest = expdest; | 6580 | dest = expdest; |
6581 | for (; dest > (char *)stackblock() && dest[-1] == '\n';) | 6581 | for (; dest > ((char *)stackblock() + startloc) && dest[-1] == '\n';) |
6582 | STUNPUTC(dest); | 6582 | STUNPUTC(dest); |
6583 | expdest = dest; | 6583 | expdest = dest; |
6584 | 6584 | ||
diff --git a/shell/ash_test/ash-psubst/tick_in_heredoc.right b/shell/ash_test/ash-psubst/tick_in_heredoc.right new file mode 100644 index 000000000..7e7bac6d3 --- /dev/null +++ b/shell/ash_test/ash-psubst/tick_in_heredoc.right | |||
@@ -0,0 +1,5 @@ | |||
1 | 1 | ||
2 | |||
3 | 2 | ||
4 | |||
5 | 3 | ||
diff --git a/shell/ash_test/ash-psubst/tick_in_heredoc.tests b/shell/ash_test/ash-psubst/tick_in_heredoc.tests new file mode 100755 index 000000000..c8eb8f4f4 --- /dev/null +++ b/shell/ash_test/ash-psubst/tick_in_heredoc.tests | |||
@@ -0,0 +1,7 @@ | |||
1 | cat <<END | ||
2 | 1 | ||
3 | $(echo "") | ||
4 | 2 | ||
5 | `echo ""` | ||
6 | 3 | ||
7 | END | ||
diff --git a/shell/hush_test/hush-psubst/tick_in_heredoc.right b/shell/hush_test/hush-psubst/tick_in_heredoc.right new file mode 100644 index 000000000..7e7bac6d3 --- /dev/null +++ b/shell/hush_test/hush-psubst/tick_in_heredoc.right | |||
@@ -0,0 +1,5 @@ | |||
1 | 1 | ||
2 | |||
3 | 2 | ||
4 | |||
5 | 3 | ||
diff --git a/shell/hush_test/hush-psubst/tick_in_heredoc.tests b/shell/hush_test/hush-psubst/tick_in_heredoc.tests new file mode 100755 index 000000000..c8eb8f4f4 --- /dev/null +++ b/shell/hush_test/hush-psubst/tick_in_heredoc.tests | |||
@@ -0,0 +1,7 @@ | |||
1 | cat <<END | ||
2 | 1 | ||
3 | $(echo "") | ||
4 | 2 | ||
5 | `echo ""` | ||
6 | 3 | ||
7 | END | ||