aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shell/ash_test/ash-quoting/dollar_altvalue2.right69
-rwxr-xr-xshell/ash_test/ash-quoting/dollar_altvalue2.tests33
-rw-r--r--shell/ash_test/ash-quoting/dollar_altvalue9.right2
-rw-r--r--shell/hush.c12
-rw-r--r--shell/hush_test/hush-quoting/dollar_altvalue2.right69
-rwxr-xr-xshell/hush_test/hush-quoting/dollar_altvalue2.tests33
-rw-r--r--shell/hush_test/hush-quoting/dollar_altvalue9.right2
7 files changed, 217 insertions, 3 deletions
diff --git a/shell/ash_test/ash-quoting/dollar_altvalue2.right b/shell/ash_test/ash-quoting/dollar_altvalue2.right
new file mode 100644
index 000000000..7cf37e379
--- /dev/null
+++ b/shell/ash_test/ash-quoting/dollar_altvalue2.right
@@ -0,0 +1,69 @@
1Unquoted '':
2start:
3||
4end
5start:
6||
7end
8start:
9||
10end
11start:
12||
13end
14start:
15||
16||
17end
18
19Unquoted "":
20start:
21||
22end
23start:
24||
25end
26start:
27||
28end
29start:
30||
31end
32start:
33||
34||
35end
36
37Quoted '':
38start:
39|''|
40end
41start:
42|'' |
43end
44start:
45| ''|
46end
47start:
48| '' |
49end
50start:
51|'' ''|
52end
53
54Quoted "":
55start:
56||
57end
58start:
59| |
60end
61start:
62| |
63end
64start:
65| |
66end
67start:
68| |
69end
diff --git a/shell/ash_test/ash-quoting/dollar_altvalue2.tests b/shell/ash_test/ash-quoting/dollar_altvalue2.tests
new file mode 100755
index 000000000..3377eb27f
--- /dev/null
+++ b/shell/ash_test/ash-quoting/dollar_altvalue2.tests
@@ -0,0 +1,33 @@
1f() { echo start:; for i; do echo "|$i|"; done; echo end; }
2x=a
3
4echo "Unquoted '':"
5f ${x:+''}
6f ${x:+'' }
7f ${x:+ ''}
8f ${x:+ '' }
9f ${x:+'' ''}
10
11echo
12echo 'Unquoted "":'
13f ${x:+""}
14f ${x:+"" }
15f ${x:+ ""}
16f ${x:+ "" }
17f ${x:+"" ""}
18
19echo
20echo "Quoted '':"
21f "${x:+''}"
22f "${x:+'' }"
23f "${x:+ ''}"
24f "${x:+ '' }"
25f "${x:+'' ''}"
26
27echo
28echo 'Quoted "":'
29f "${x:+""}"
30f "${x:+"" }"
31f "${x:+ ""}"
32f "${x:+ "" }"
33f "${x:+"" ""}"
diff --git a/shell/ash_test/ash-quoting/dollar_altvalue9.right b/shell/ash_test/ash-quoting/dollar_altvalue9.right
index fc6c2697c..39342fe7c 100644
--- a/shell/ash_test/ash-quoting/dollar_altvalue9.right
+++ b/shell/ash_test/ash-quoting/dollar_altvalue9.right
@@ -3,6 +3,7 @@ Unquoted 1:
3|x y| 3|x y|
4|1| 4|1|
5|2| 5|2|
6||
6|1 2| 7|1 2|
7|A| 8|A|
8|B| 9|B|
@@ -14,6 +15,7 @@ Unquoted 2:
14|ax y| 15|ax y|
15|1| 16|1|
16|2| 17|2|
18||
17|1 2| 19|1 2|
18|A| 20|A|
19|B| 21|B|
diff --git a/shell/hush.c b/shell/hush.c
index fc77b89fc..559595d2e 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -475,7 +475,6 @@
475#endif 475#endif
476 476
477#define SPECIAL_VAR_SYMBOL_STR "\3" 477#define SPECIAL_VAR_SYMBOL_STR "\3"
478#define SPECIAL_VAR_SYMBOL_CHR '\3'
479#define SPECIAL_VAR_SYMBOL 3 478#define SPECIAL_VAR_SYMBOL 3
480/* The "variable" with name "\1" emits string "\3". Testcase: "echo ^C" */ 479/* The "variable" with name "\1" emits string "\3". Testcase: "echo ^C" */
481#define SPECIAL_VAR_QUOTED_SVS 1 480#define SPECIAL_VAR_QUOTED_SVS 1
@@ -5950,6 +5949,8 @@ static int encode_then_append_var_plusminus(o_string *output, int n,
5950 break; 5949 break;
5951 o_addqchr(&dest, ch); 5950 o_addqchr(&dest, ch);
5952 } 5951 }
5952 o_addchr(&dest, SPECIAL_VAR_SYMBOL);
5953 o_addchr(&dest, SPECIAL_VAR_SYMBOL);
5953 continue; 5954 continue;
5954 } 5955 }
5955 } 5956 }
@@ -5959,6 +5960,10 @@ static int encode_then_append_var_plusminus(o_string *output, int n,
5959 } 5960 }
5960 if (ch == '"') { 5961 if (ch == '"') {
5961 dest.o_expflags ^= EXP_FLAG_ESC_GLOB_CHARS; 5962 dest.o_expflags ^= EXP_FLAG_ESC_GLOB_CHARS;
5963 if (dest.o_expflags) {
5964 o_addchr(&dest, SPECIAL_VAR_SYMBOL);
5965 o_addchr(&dest, SPECIAL_VAR_SYMBOL);
5966 }
5962 continue; 5967 continue;
5963 } 5968 }
5964 if (ch == '\\') { 5969 if (ch == '\\') {
@@ -6565,7 +6570,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
6565 case SPECIAL_VAR_QUOTED_SVS: 6570 case SPECIAL_VAR_QUOTED_SVS:
6566 /* <SPECIAL_VAR_SYMBOL><SPECIAL_VAR_QUOTED_SVS><SPECIAL_VAR_SYMBOL> */ 6571 /* <SPECIAL_VAR_SYMBOL><SPECIAL_VAR_QUOTED_SVS><SPECIAL_VAR_SYMBOL> */
6567 /* "^C variable", represents literal ^C char (possible in scripts) */ 6572 /* "^C variable", represents literal ^C char (possible in scripts) */
6568 o_addchr(output, SPECIAL_VAR_SYMBOL_CHR); 6573 o_addchr(output, SPECIAL_VAR_SYMBOL);
6569 arg++; 6574 arg++;
6570 break; 6575 break;
6571#if ENABLE_HUSH_TICK 6576#if ENABLE_HUSH_TICK
@@ -6627,7 +6632,8 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
6627 o_addstr(output, arg); 6632 o_addstr(output, arg);
6628 debug_print_list("expand_vars_to_list[b]", output, n); 6633 debug_print_list("expand_vars_to_list[b]", output, n);
6629 } else if (output->length == o_get_last_ptr(output, n) /* expansion is empty */ 6634 } else if (output->length == o_get_last_ptr(output, n) /* expansion is empty */
6630 && !(cant_be_null & 0x80) /* and all vars were not quoted. */ 6635 && !(cant_be_null & 0x80) /* and all vars were not quoted */
6636 && !output->has_quoted_part
6631 ) { 6637 ) {
6632 n--; 6638 n--;
6633 /* allow to reuse list[n] later without re-growth */ 6639 /* allow to reuse list[n] later without re-growth */
diff --git a/shell/hush_test/hush-quoting/dollar_altvalue2.right b/shell/hush_test/hush-quoting/dollar_altvalue2.right
new file mode 100644
index 000000000..7cf37e379
--- /dev/null
+++ b/shell/hush_test/hush-quoting/dollar_altvalue2.right
@@ -0,0 +1,69 @@
1Unquoted '':
2start:
3||
4end
5start:
6||
7end
8start:
9||
10end
11start:
12||
13end
14start:
15||
16||
17end
18
19Unquoted "":
20start:
21||
22end
23start:
24||
25end
26start:
27||
28end
29start:
30||
31end
32start:
33||
34||
35end
36
37Quoted '':
38start:
39|''|
40end
41start:
42|'' |
43end
44start:
45| ''|
46end
47start:
48| '' |
49end
50start:
51|'' ''|
52end
53
54Quoted "":
55start:
56||
57end
58start:
59| |
60end
61start:
62| |
63end
64start:
65| |
66end
67start:
68| |
69end
diff --git a/shell/hush_test/hush-quoting/dollar_altvalue2.tests b/shell/hush_test/hush-quoting/dollar_altvalue2.tests
new file mode 100755
index 000000000..3377eb27f
--- /dev/null
+++ b/shell/hush_test/hush-quoting/dollar_altvalue2.tests
@@ -0,0 +1,33 @@
1f() { echo start:; for i; do echo "|$i|"; done; echo end; }
2x=a
3
4echo "Unquoted '':"
5f ${x:+''}
6f ${x:+'' }
7f ${x:+ ''}
8f ${x:+ '' }
9f ${x:+'' ''}
10
11echo
12echo 'Unquoted "":'
13f ${x:+""}
14f ${x:+"" }
15f ${x:+ ""}
16f ${x:+ "" }
17f ${x:+"" ""}
18
19echo
20echo "Quoted '':"
21f "${x:+''}"
22f "${x:+'' }"
23f "${x:+ ''}"
24f "${x:+ '' }"
25f "${x:+'' ''}"
26
27echo
28echo 'Quoted "":'
29f "${x:+""}"
30f "${x:+"" }"
31f "${x:+ ""}"
32f "${x:+ "" }"
33f "${x:+"" ""}"
diff --git a/shell/hush_test/hush-quoting/dollar_altvalue9.right b/shell/hush_test/hush-quoting/dollar_altvalue9.right
index fc6c2697c..39342fe7c 100644
--- a/shell/hush_test/hush-quoting/dollar_altvalue9.right
+++ b/shell/hush_test/hush-quoting/dollar_altvalue9.right
@@ -3,6 +3,7 @@ Unquoted 1:
3|x y| 3|x y|
4|1| 4|1|
5|2| 5|2|
6||
6|1 2| 7|1 2|
7|A| 8|A|
8|B| 9|B|
@@ -14,6 +15,7 @@ Unquoted 2:
14|ax y| 15|ax y|
15|1| 16|1|
16|2| 17|2|
18||
17|1 2| 19|1 2|
18|A| 20|A|
19|B| 21|B|