Correctly split path environment variables about colons

As noted in #5271
This commit is contained in:
ridiculousfish 2018-10-27 15:20:32 -07:00
parent 47890389e1
commit 9454397e4c
3 changed files with 25 additions and 13 deletions

View file

@ -1035,6 +1035,15 @@ static void env_set_internal_universal(const wcstring &key, wcstring_list_t val,
var_mode |= (dopathvar ? ENV_PATHVAR : ENV_UNPATHVAR);
}
// Split about ':' if it's a path variable.
if (var_mode & ENV_PATHVAR) {
wcstring_list_t split_val;
for (const wcstring &str : val) {
vec_append(split_val, split_string(str, PATH_ARRAY_SEP));
}
val = std::move(split_val);
}
// Construct and set the new variable.
env_var_t::env_var_flags_t varflags = 0;
if (var_mode & ENV_EXPORT) varflags |= env_var_t::flag_export;

View file

@ -312,17 +312,18 @@ set -x DONT_ESCAPE_SPACES '1 ' '2 ' ' 3 ' 4 ; env | grep '^DONT_ESCAPE_SPACES='
set -x DONT_ESCAPE_COLONS_PATH 1: 2: :3: ; env | grep '^DONT_ESCAPE_COLONS_PATH='
logmsg Path universal variables
set __fish_test_path_not a b c
set __fish_test_PATH 1 2 3
echo "$__fish_test_path_not $__fish_test_PATH"
set -U __fish_test_path_not a b c
set -U __fish_test_PATH 1 2 3
echo "$__fish_test_path_not $__fish_test_PATH" $__fish_test_path_not $__fish_test_PATH
set --unpath __fish_test_PATH $__fish_test_PATH
echo "$__fish_test_path_not $__fish_test_PATH"
echo "$__fish_test_path_not $__fish_test_PATH" $__fish_test_path_not $__fish_test_PATH
set --path __fish_test_path_not $__fish_test_path_not
echo "$__fish_test_path_not $__fish_test_PATH"
echo "$__fish_test_path_not $__fish_test_PATH" $__fish_test_path_not $__fish_test_PATH
set --path __fish_test_PATH $__fish_test_PATH
echo "$__fish_test_path_not $__fish_test_PATH"
echo "$__fish_test_path_not $__fish_test_PATH" $__fish_test_path_not $__fish_test_PATH
set -U __fish_test_PATH 1:2:3
echo "$__fish_test_PATH" $__fish_test_PATH
set -U --path __fish_test_path2 a:b
echo "$__fish_test_path2" $__fish_test_path2
true

View file

@ -49,7 +49,9 @@ DONT_ESCAPE_COLONS_PATH=1::2:::3:
####################
# Path universal variables
a b c 1:2:3
a b c 1 2 3
a:b:c 1 2 3
a:b:c 1:2:3
a b c 1:2:3 a b c 1 2 3
a b c 1 2 3 a b c 1 2 3
a:b:c 1 2 3 a b c 1 2 3
a:b:c 1:2:3 a b c 1 2 3
1:2:3 1 2 3
a:b a b