From 9454397e4c30982db5b75b26267bcc3af1e1d749 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 27 Oct 2018 15:20:32 -0700 Subject: [PATCH] Correctly split path environment variables about colons As noted in #5271 --- src/env.cpp | 9 +++++++++ tests/test3.in | 19 ++++++++++--------- tests/test3.out | 10 ++++++---- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/env.cpp b/src/env.cpp index d6ec3bc27..c3e8b97be 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -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; diff --git a/tests/test3.in b/tests/test3.in index e4d8c2b42..12cfa41b0 100644 --- a/tests/test3.in +++ b/tests/test3.in @@ -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 diff --git a/tests/test3.out b/tests/test3.out index 9c8bfd2da..ef5cf91cd 100644 --- a/tests/test3.out +++ b/tests/test3.out @@ -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