patch 9.1.1572: expanding $var does not escape whitespace for 'path'
Commit:
https://github.com/vim/vim/commit/8b004081c4cd3788c3685420cbbe3b45e609724f
Author: Miguel Barro <[email protected]>
Date: Sun Jul 20 10:47:14 2025 +0200
patch 9.1.1572: expanding $var does not escape whitespace for 'path'
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 <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/option.c b/src/option.c
index a7d87f37b..978fc0bf2 100644
--- a/src/option.c
+++ b/src/option.c
@@ -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
diff --git a/src/testdir/test_findfile.vim b/src/testdir/test_findfile.vim
index acb26e0e5..42c3fb643 100644
--- a/src/testdir/test_findfile.vim
+++ b/src/testdir/test_findfile.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 382ab20bb..b35dac242 100644
--- a/src/version.c
+++ b/src/version.c
@@ -719,6 +719,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1572,
/**/
1571,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1udPtr-00GrkN-Is%40256bit.org.