BUG/MEDIUM: config: for word expansion, empty or non-existing are the same

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.
This commit is contained in:
Willy Tarreau 2025-11-10 11:55:33 +01:00
parent b26a6d50c6
commit 137d5ba93f

View File

@ -6430,6 +6430,15 @@ uint32_t parse_line(char *in, char *out, size_t *outlen, char **args, int *nbarg
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) {
@ -6461,16 +6470,7 @@ uint32_t parse_line(char *in, char *out, size_t *outlen, char **args, int *nbarg
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.
*/