Amaury reported a case where "${FOO[*]}" still produces an empty field.
It happens if the variable is defined but does not contain any non-space
characters. The reason is that we special-case word expansion only on
non-existing vars. Let's change the ordering of operations so that word-
expanded vars always pretend the current arg is not an empty quote, so
that we don't make any difference between a non-existing var and an
empty one.
No backport is needed unless commit
1968731765 ("BUG/MEDIUM: config:
solve the empty argument problem again") is.
brace = NULL;
}
+ if (word_expand) {
+ /* If an empty or unknown env variable was passed as an array,
+ * we pretend the quotes were not empty, which will be sufficient
+ * to avoid creating a new arg. This is permitted and results
+ * in not creating any arg and dropping the surrounding quotes.
+ */
+ empty_quote = 0;
+ }
+
if (value) {
unknown_var_name = NULL;
while (*value) {
arg_start = outpos;
}
}
- else if (word_expand) {
- /* An empty or unknown env variable was passed as an array.
- * This is permitted and results in not creating any arg and
- * dropping the surrounding quotes. Here we pretend the quotes
- * were not empty, which will be sufficient to avoid creating
- * a new arg.
- */
- empty_quote = 0;
- }
- else {
+ else if (!word_expand) {
/* An unmatched environment variable was parsed, it must
* count as an argument.
*/