]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1572: expanding $var does not escape whitespace for 'path' v9.1.1572
authorMiguel Barro <miguel.barro@live.com>
Sun, 20 Jul 2025 08:47:14 +0000 (10:47 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 20 Jul 2025 08:47:14 +0000 (10:47 +0200)
Problem:  expanding $var does not escape whitespace for 'path'
Solution: Escape whitespace when expanding 'path' option.
          (Miguel Barro)

closes: #17801

Signed-off-by: Miguel Barro <miguel.barro@live.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/option.c
src/testdir/test_findfile.vim
src/version.c

index a7d87f37b64fb290e4b4e0dc8e48d59200da8d28..978fc0bf237ca617c9ae6956eff7477cc1cb5ab4 100644 (file)
@@ -2927,14 +2927,16 @@ option_expand(int opt_idx, char_u *val)
 
     /*
      * Expanding this with NameBuff, expand_env() must not be passed IObuff.
-     * Escape spaces when expanding 'tags', they are used to separate file
-     * names.
+     * Escape spaces when expanding 'tags' or 'path', they are used to separate
+     * file names.
      * For 'spellsuggest' expand after "file:".
      */
-    expand_env_esc(val, NameBuff, MAXPATHL,
-           (char_u **)options[opt_idx].var == &p_tags, FALSE,
+    char_u ** var = (char_u **)options[opt_idx].var;
+    int esc = var == &p_tags || var == &p_path;
+
+    expand_env_esc(val, NameBuff, MAXPATHL, esc, FALSE,
 #ifdef FEAT_SPELL
-           (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
+           var == &p_sps ? (char_u *)"file:" :
 #endif
                                  NULL);
     if (STRCMP(NameBuff, val) == 0)   // they are the same
index acb26e0e5e642a0153129cef7149fdd484514e80..42c3fb64315861f29a811e11cfd894f1fc189cd0 100644 (file)
@@ -834,5 +834,36 @@ func Test_findfunc_callback()
   %bw!
 endfunc
 
+" Test using environment variables with spaces
+func Test_path_env_variable_with_whitespaces()
+    let save_path = &path
+    defer execute('let &path = save_path')
+
+    let $testdir = 'Xpath with some whites'
+    call mkdir($testdir, 'R')
+
+    " Check direct usage yields the same result that autocomplete
+    call feedkeys(':set path=$testdir' .. "\<C-A>\<CR>", 'xt')
+    let auto_testpath = &path
+    " include autocomplete suffix
+    exe "set path=$testdir" .. "/"
+    call assert_equal(auto_testpath, &path)
+
+    " Check a file can be found using environment variables
+    let expanded_test_path = expand('$testdir/test.txt')
+    call writefile(['testing...'], expanded_test_path)
+
+    " hinting an environment variable path
+    call assert_equal(expanded_test_path, findfile('test.txt', $test_dir))
+
+    " using 'path' option with an environment variable
+    set path=$testdir
+    call assert_equal(expanded_test_path, findfile('test.txt'))
+
+    " using :find instead of findfile()
+    find test.txt
+    call assert_equal(expanded_test_path, expand('%:.'))
+    enew
+endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index 382ab20bbd9bf5901737520ed3f4dc4a032d39b3..b35dac24278bdf5ea0571d23f2bdf50d9dfa6617 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1572,
 /**/
     1571,
 /**/