Merge pull request #1487 from michich/fix-env-expansion

Fix env expansion
This commit is contained in:
Lennart Poettering 2015-10-07 15:54:04 +03:00
commit 5530caa20b
3 changed files with 7 additions and 3 deletions

View file

@ -993,7 +993,7 @@
<literal>$FOO</literal> as a separate word on the command line, in
which case it will be replaced by the value of the environment
variable split at whitespace resulting in zero or more arguments.
For this type of expansion, quotes and respected when splitting
For this type of expansion, quotes are respected when splitting
into words, and afterwards removed.</para>
<para>Example:</para>

View file

@ -541,7 +541,7 @@ char **replace_env_argv(char **argv, char **env) {
STRV_FOREACH(i, argv) {
/* If $FOO appears as single word, replace it by the split up variable */
if ((*i)[0] == '$' && (*i)[1] != '{') {
if ((*i)[0] == '$' && (*i)[1] != '{' && (*i)[1] != '$') {
char *e;
char **w, **m = NULL;
unsigned q;

View file

@ -118,6 +118,8 @@ static void test_replace_env_arg(void) {
"$FOO$FOO",
"${FOO}${BAR}",
"${FOO",
"FOO$$${FOO}",
"$$FOO${FOO}",
NULL
};
_cleanup_strv_free_ char **r = NULL;
@ -133,7 +135,9 @@ static void test_replace_env_arg(void) {
assert_se(streq(r[6], "BAR"));
assert_se(streq(r[7], "BAR BARwaldo"));
assert_se(streq(r[8], "${FOO"));
assert_se(strv_length(r) == 9);
assert_se(streq(r[9], "FOO$BAR BAR"));
assert_se(streq(r[10], "$FOOBAR BAR"));
assert_se(strv_length(r) == 11);
}
static void test_env_clean(void) {