]> granicus.if.org Git - vim/commitdiff
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars v8.2.0239
authorBram Moolenaar <Bram@vim.org>
Mon, 10 Feb 2020 21:06:32 +0000 (22:06 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 10 Feb 2020 21:06:32 +0000 (22:06 +0100)
Problem:    MS-Windows: 'env' job option does not override existing
            environment variables.  (Tim Pope)
Solution:   Set the environment variables later. (Yasuhiro Matsumoto,
            closes #5485, closes #5608)

src/os_win32.c
src/testdir/test_channel.vim
src/version.c

index 2594aeea56a7048948161041c12f55f478517bc4..f394979d60a834777f4a59545a34c12bc51ea7e7 100644 (file)
@@ -4948,24 +4948,6 @@ win32_build_env(dict_T *env, garray_T *gap, int is_terminal)
     if (ga_grow(gap, 1) == FAIL)
        return;
 
-    if (base)
-    {
-       WCHAR   *p = (WCHAR*) base;
-
-       // for last \0
-       if (ga_grow(gap, 1) == FAIL)
-           return;
-
-       while (*p != 0 || *(p + 1) != 0)
-       {
-           if (ga_grow(gap, 1) == OK)
-               *((WCHAR*)gap->ga_data + gap->ga_len++) = *p;
-           p++;
-       }
-       FreeEnvironmentStrings(base);
-       *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
-    }
-
     if (env != NULL)
     {
        for (hi = env->dv_hashtab.ht_array; todo > 0; ++hi)
@@ -4997,6 +4979,24 @@ win32_build_env(dict_T *env, garray_T *gap, int is_terminal)
        }
     }
 
+    if (base)
+    {
+       WCHAR   *p = (WCHAR*) base;
+
+       // for last \0
+       if (ga_grow(gap, 1) == FAIL)
+           return;
+
+       while (*p != 0 || *(p + 1) != 0)
+       {
+           if (ga_grow(gap, 1) == OK)
+               *((WCHAR*)gap->ga_data + gap->ga_len++) = *p;
+           p++;
+       }
+       FreeEnvironmentStrings(base);
+       *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
+    }
+
 # if defined(FEAT_CLIENTSERVER) || defined(FEAT_TERMINAL)
     {
 #  ifdef FEAT_CLIENTSERVER
index ebcd76e0ffef836c70fda74a6a3dc346076df7bb..16fe5c7829fc7052581b2980f9c5dd3382e35a81 100644 (file)
@@ -2006,3 +2006,12 @@ func Test_issue_5150()
   sleep 10m
   call assert_equal(-1, job_info(g:job).exitval)
 endfunc
+
+func Test_issue_5485()
+  let $VAR1 = 'global'
+  let g:Ch_reply = ""
+  let l:job = job_start([&shell, &shellcmdflag, has('win32') ? 'echo %VAR1% %VAR2%' : 'echo $VAR1 $VAR2'], {'env': {'VAR1': 'local', 'VAR2': 'local'}, 'callback': 'Ch_handler'})
+  let g:Ch_job = l:job
+  call WaitForAssert({-> assert_equal("local local", trim(g:Ch_reply))})
+  unlet $VAR1
+endfunc
index 61a9f958a4c7aaad1438e20d485f5bb3bdec9719..cf96f4051453af03b8e29d7da1ca8f0192d4388d 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    239,
 /**/
     238,
 /**/