mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 23:21:22 +03:00
basic/env-util: correctly parse extended vars after non-extended vars (#20941)
This commit is contained in:
parent
8ac04a6547
commit
5ef97a7122
@ -615,6 +615,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
||||
|
||||
word = e+1;
|
||||
state = WORD;
|
||||
nest--;
|
||||
} else if (*e == ':') {
|
||||
if (flags & REPLACE_ENV_ALLOW_EXTENDED) {
|
||||
len = e - word - 2;
|
||||
|
@ -217,7 +217,7 @@ static void test_replace_env2(bool extended) {
|
||||
"BAR=bar",
|
||||
NULL
|
||||
};
|
||||
_cleanup_free_ char *t = NULL, *s = NULL, *q = NULL, *r = NULL, *p = NULL, *x = NULL;
|
||||
_cleanup_free_ char *t = NULL, *s = NULL, *q = NULL, *r = NULL, *p = NULL, *x = NULL, *y = NULL;
|
||||
unsigned flags = REPLACE_ENV_ALLOW_EXTENDED*extended;
|
||||
|
||||
t = replace_env("FOO=${FOO:-${BAR}}", (char**) env, flags);
|
||||
@ -237,6 +237,9 @@ static void test_replace_env2(bool extended) {
|
||||
|
||||
x = replace_env("XXX=${XXX:+${BAR}post}", (char**) env, flags);
|
||||
assert_se(streq(x, extended ? "XXX=" : "XXX=${XXX:+barpost}"));
|
||||
|
||||
y = replace_env("FOO=${FOO}between${BAR:-baz}", (char**) env, flags);
|
||||
assert_se(streq(y, extended ? "FOO=foobetweenbar" : "FOO=foobetween${BAR:-baz}"));
|
||||
}
|
||||
|
||||
static void test_replace_env_argv(void) {
|
||||
|
Loading…
Reference in New Issue
Block a user