diff options
-rw-r--r-- | shell/ash_test/ash-quoting/dollar_altvalue2.right | 69 | ||||
-rwxr-xr-x | shell/ash_test/ash-quoting/dollar_altvalue2.tests | 33 | ||||
-rw-r--r-- | shell/ash_test/ash-quoting/dollar_altvalue9.right | 2 | ||||
-rw-r--r-- | shell/hush.c | 12 | ||||
-rw-r--r-- | shell/hush_test/hush-quoting/dollar_altvalue2.right | 69 | ||||
-rwxr-xr-x | shell/hush_test/hush-quoting/dollar_altvalue2.tests | 33 | ||||
-rw-r--r-- | shell/hush_test/hush-quoting/dollar_altvalue9.right | 2 |
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 @@ | |||
1 | Unquoted '': | ||
2 | start: | ||
3 | || | ||
4 | end | ||
5 | start: | ||
6 | || | ||
7 | end | ||
8 | start: | ||
9 | || | ||
10 | end | ||
11 | start: | ||
12 | || | ||
13 | end | ||
14 | start: | ||
15 | || | ||
16 | || | ||
17 | end | ||
18 | |||
19 | Unquoted "": | ||
20 | start: | ||
21 | || | ||
22 | end | ||
23 | start: | ||
24 | || | ||
25 | end | ||
26 | start: | ||
27 | || | ||
28 | end | ||
29 | start: | ||
30 | || | ||
31 | end | ||
32 | start: | ||
33 | || | ||
34 | || | ||
35 | end | ||
36 | |||
37 | Quoted '': | ||
38 | start: | ||
39 | |''| | ||
40 | end | ||
41 | start: | ||
42 | |'' | | ||
43 | end | ||
44 | start: | ||
45 | | ''| | ||
46 | end | ||
47 | start: | ||
48 | | '' | | ||
49 | end | ||
50 | start: | ||
51 | |'' ''| | ||
52 | end | ||
53 | |||
54 | Quoted "": | ||
55 | start: | ||
56 | || | ||
57 | end | ||
58 | start: | ||
59 | | | | ||
60 | end | ||
61 | start: | ||
62 | | | | ||
63 | end | ||
64 | start: | ||
65 | | | | ||
66 | end | ||
67 | start: | ||
68 | | | | ||
69 | end | ||
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 @@ | |||
1 | f() { echo start:; for i; do echo "|$i|"; done; echo end; } | ||
2 | x=a | ||
3 | |||
4 | echo "Unquoted '':" | ||
5 | f ${x:+''} | ||
6 | f ${x:+'' } | ||
7 | f ${x:+ ''} | ||
8 | f ${x:+ '' } | ||
9 | f ${x:+'' ''} | ||
10 | |||
11 | echo | ||
12 | echo 'Unquoted "":' | ||
13 | f ${x:+""} | ||
14 | f ${x:+"" } | ||
15 | f ${x:+ ""} | ||
16 | f ${x:+ "" } | ||
17 | f ${x:+"" ""} | ||
18 | |||
19 | echo | ||
20 | echo "Quoted '':" | ||
21 | f "${x:+''}" | ||
22 | f "${x:+'' }" | ||
23 | f "${x:+ ''}" | ||
24 | f "${x:+ '' }" | ||
25 | f "${x:+'' ''}" | ||
26 | |||
27 | echo | ||
28 | echo 'Quoted "":' | ||
29 | f "${x:+""}" | ||
30 | f "${x:+"" }" | ||
31 | f "${x:+ ""}" | ||
32 | f "${x:+ "" }" | ||
33 | f "${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 @@ | |||
1 | Unquoted '': | ||
2 | start: | ||
3 | || | ||
4 | end | ||
5 | start: | ||
6 | || | ||
7 | end | ||
8 | start: | ||
9 | || | ||
10 | end | ||
11 | start: | ||
12 | || | ||
13 | end | ||
14 | start: | ||
15 | || | ||
16 | || | ||
17 | end | ||
18 | |||
19 | Unquoted "": | ||
20 | start: | ||
21 | || | ||
22 | end | ||
23 | start: | ||
24 | || | ||
25 | end | ||
26 | start: | ||
27 | || | ||
28 | end | ||
29 | start: | ||
30 | || | ||
31 | end | ||
32 | start: | ||
33 | || | ||
34 | || | ||
35 | end | ||
36 | |||
37 | Quoted '': | ||
38 | start: | ||
39 | |''| | ||
40 | end | ||
41 | start: | ||
42 | |'' | | ||
43 | end | ||
44 | start: | ||
45 | | ''| | ||
46 | end | ||
47 | start: | ||
48 | | '' | | ||
49 | end | ||
50 | start: | ||
51 | |'' ''| | ||
52 | end | ||
53 | |||
54 | Quoted "": | ||
55 | start: | ||
56 | || | ||
57 | end | ||
58 | start: | ||
59 | | | | ||
60 | end | ||
61 | start: | ||
62 | | | | ||
63 | end | ||
64 | start: | ||
65 | | | | ||
66 | end | ||
67 | start: | ||
68 | | | | ||
69 | end | ||
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 @@ | |||
1 | f() { echo start:; for i; do echo "|$i|"; done; echo end; } | ||
2 | x=a | ||
3 | |||
4 | echo "Unquoted '':" | ||
5 | f ${x:+''} | ||
6 | f ${x:+'' } | ||
7 | f ${x:+ ''} | ||
8 | f ${x:+ '' } | ||
9 | f ${x:+'' ''} | ||
10 | |||
11 | echo | ||
12 | echo 'Unquoted "":' | ||
13 | f ${x:+""} | ||
14 | f ${x:+"" } | ||
15 | f ${x:+ ""} | ||
16 | f ${x:+ "" } | ||
17 | f ${x:+"" ""} | ||
18 | |||
19 | echo | ||
20 | echo "Quoted '':" | ||
21 | f "${x:+''}" | ||
22 | f "${x:+'' }" | ||
23 | f "${x:+ ''}" | ||
24 | f "${x:+ '' }" | ||
25 | f "${x:+'' ''}" | ||
26 | |||
27 | echo | ||
28 | echo 'Quoted "":' | ||
29 | f "${x:+""}" | ||
30 | f "${x:+"" }" | ||
31 | f "${x:+ ""}" | ||
32 | f "${x:+ "" }" | ||
33 | f "${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| |