3 @@ -1853,7 +1853,7 @@ static void o_addblock_duplicate_backsla
7 - && (*str != '*' && *str != '?' && *str != '[')
8 +// && (*str != '*' && *str != '?' && *str != '[')
12 @@ -2834,18 +2834,22 @@ static NOINLINE int expand_vars_to_list(
16 -static char **expand_variables(char **argv, int or_mask)
18 + EXPVAR_FLAG_GLOB = 0x200,
19 + EXPVAR_FLAG_ESCAPE_VARS = 0x100,
20 + EXPVAR_FLAG_SINGLEWORD = 0x80, /* must be 0x80 */
22 +static char **expand_variables(char **argv, unsigned or_mask)
27 o_string output = NULL_O_STRING;
29 - if (or_mask & 0x100) {
30 - output.o_escape = 1; /* protect against globbing for "$var" */
31 - /* (unquoted $var will temporarily switch it off) */
34 + /* protect against globbing for "$var"? */
35 + /* (unquoted $var will temporarily switch it off) */
36 + output.o_escape = 1 & (or_mask / EXPVAR_FLAG_ESCAPE_VARS);
37 + output.o_glob = 1 & (or_mask / EXPVAR_FLAG_GLOB);
41 @@ -2863,13 +2867,13 @@ static char **expand_variables(char **ar
43 static char **expand_strvec_to_strvec(char **argv)
45 - return expand_variables(argv, 0x100);
46 + return expand_variables(argv, EXPVAR_FLAG_GLOB | EXPVAR_FLAG_ESCAPE_VARS);
49 #if ENABLE_HUSH_BASH_COMPAT
50 static char **expand_strvec_to_strvec_singleword_noglob(char **argv)
52 - return expand_variables(argv, 0x80);
53 + return expand_variables(argv, EXPVAR_FLAG_SINGLEWORD);
57 @@ -2909,15 +2913,15 @@ static char **expand_strvec_to_strvec_si
60 /* Used for expansion of right hand of assignments */
61 -/* NB: should NOT do globbing! "export v=/bin/c*; env | grep ^v=" outputs
63 +/* NB: should NOT do globbing!
64 + * "export v=/bin/c*; env | grep ^v=" outputs "v=/bin/c*" */
65 static char *expand_string_to_string(const char *str)
67 char *argv[2], **list;
71 - list = expand_variables(argv, 0x80); /* 0x80: singleword expansion */
72 + list = expand_variables(argv, EXPVAR_FLAG_ESCAPE_VARS | EXPVAR_FLAG_SINGLEWORD);
74 if (!list[0] || list[1])
75 bb_error_msg_and_die("BUG in varexp2");
76 @@ -2933,7 +2937,7 @@ static char* expand_strvec_to_string(cha
80 - list = expand_variables(argv, 0x80);
81 + list = expand_variables(argv, EXPVAR_FLAG_SINGLEWORD);
82 /* Convert all NULs to spaces */
86 +++ b/shell/hush_test/hush-vars/var_unbackslash.right
88 +b1=-qwerty-t-\-"---z-*-?-
89 +b1=-qwerty-t-\-"---z-*-?-
90 +b2=-$a-\t-\\-\"-\--\z-\*-\?-
91 +b2=-$a-\t-\\-\"-\--\z-\*-\?-
92 +c=-$a-\t-\\-\"-\--\z-\*-\?-
93 +c=-$a-\t-\\-\"-\--\z-\*-\?-
94 +c=-$a-\t-\\-\"-\--\z-\*-\?-
95 +c=-$a-\t-\\-\"-\--\z-\*-\?-
98 +++ b/shell/hush_test/hush-vars/var_unbackslash.tests
100 +# Test for correct handling of backslashes
103 +b=-$a-\t-\\-\"-\--\z-\*-\?-
106 +b='-$a-\t-\\-\"-\--\z-\*-\?-'