[git commit] hush: fix expansion of space in "a=${a:+$a }c" construct

Denys Vlasenko vda.linux at googlemail.com
Mon Jun 12 14:39:32 UTC 2023


commit: https://git.busybox.net/busybox/commit/?id=bab8828b0dad1d51d6b34e38249f0641ca64b1e9
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
encode_then_append_var_plusminus                     554     552      -2

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash_test/ash-quoting/space_in_varexp1.right   | 2 ++
 shell/ash_test/ash-quoting/space_in_varexp1.tests   | 6 ++++++
 shell/hush.c                                        | 2 +-
 shell/hush_test/hush-quoting/space_in_varexp1.right | 2 ++
 shell/hush_test/hush-quoting/space_in_varexp1.tests | 6 ++++++
 5 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/shell/ash_test/ash-quoting/space_in_varexp1.right b/shell/ash_test/ash-quoting/space_in_varexp1.right
new file mode 100644
index 000000000..a617a91c3
--- /dev/null
+++ b/shell/ash_test/ash-quoting/space_in_varexp1.right
@@ -0,0 +1,2 @@
+1:'b c'
+2:'b c'
diff --git a/shell/ash_test/ash-quoting/space_in_varexp1.tests b/shell/ash_test/ash-quoting/space_in_varexp1.tests
new file mode 100755
index 000000000..1589587d1
--- /dev/null
+++ b/shell/ash_test/ash-quoting/space_in_varexp1.tests
@@ -0,0 +1,6 @@
+a=b
+a=${a:+$a }c
+echo "1:'$a'"
+a=b
+a="${a:+$a }c"
+echo "2:'$a'"
diff --git a/shell/hush.c b/shell/hush.c
index cdaa67a3b..dbc4aecab 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -6398,7 +6398,7 @@ static NOINLINE int encode_then_append_var_plusminus(o_string *output, int n,
 		if (!dest.o_expflags) {
 			if (ch == EOF)
 				break;
-			if (!dquoted && strchr(G.ifs, ch)) {
+			if (!dquoted && !(output->o_expflags & EXP_FLAG_SINGLEWORD) && strchr(G.ifs, ch)) {
 				/* PREFIX${x:d${e}f ...} and we met space: expand "d${e}f" and start new word.
 				 * do not assume we are at the start of the word (PREFIX above).
 				 */
diff --git a/shell/hush_test/hush-quoting/space_in_varexp1.right b/shell/hush_test/hush-quoting/space_in_varexp1.right
new file mode 100644
index 000000000..a617a91c3
--- /dev/null
+++ b/shell/hush_test/hush-quoting/space_in_varexp1.right
@@ -0,0 +1,2 @@
+1:'b c'
+2:'b c'
diff --git a/shell/hush_test/hush-quoting/space_in_varexp1.tests b/shell/hush_test/hush-quoting/space_in_varexp1.tests
new file mode 100755
index 000000000..1589587d1
--- /dev/null
+++ b/shell/hush_test/hush-quoting/space_in_varexp1.tests
@@ -0,0 +1,6 @@
+a=b
+a=${a:+$a }c
+echo "1:'$a'"
+a=b
+a="${a:+$a }c"
+echo "2:'$a'"


More information about the busybox-cvs mailing list