Skip to content

Commit 8b00408

Browse files
MiguelBarrochrisbra
authored andcommitted
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]>
1 parent 239c4e4 commit 8b00408

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

src/option.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,14 +2927,16 @@ option_expand(int opt_idx, char_u *val)
29272927

29282928
/*
29292929
* Expanding this with NameBuff, expand_env() must not be passed IObuff.
2930-
* Escape spaces when expanding 'tags', they are used to separate file
2931-
* names.
2930+
* Escape spaces when expanding 'tags' or 'path', they are used to separate
2931+
* file names.
29322932
* For 'spellsuggest' expand after "file:".
29332933
*/
2934-
expand_env_esc(val, NameBuff, MAXPATHL,
2935-
(char_u **)options[opt_idx].var == &p_tags, FALSE,
2934+
char_u ** var = (char_u **)options[opt_idx].var;
2935+
int esc = var == &p_tags || var == &p_path;
2936+
2937+
expand_env_esc(val, NameBuff, MAXPATHL, esc, FALSE,
29362938
#ifdef FEAT_SPELL
2937-
(char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
2939+
var == &p_sps ? (char_u *)"file:" :
29382940
#endif
29392941
NULL);
29402942
if (STRCMP(NameBuff, val) == 0) // they are the same

src/testdir/test_findfile.vim

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,5 +834,36 @@ func Test_findfunc_callback()
834834
%bw!
835835
endfunc
836836

837+
" Test using environment variables with spaces
838+
func Test_path_env_variable_with_whitespaces()
839+
let save_path = &path
840+
defer execute('let &path = save_path')
841+
842+
let $testdir = 'Xpath with some whites'
843+
call mkdir($testdir, 'R')
844+
845+
" Check direct usage yields the same result that autocomplete
846+
call feedkeys(':set path=$testdir' .. "\<C-A>\<CR>", 'xt')
847+
let auto_testpath = &path
848+
" include autocomplete suffix
849+
exe "set path=$testdir" .. "/"
850+
call assert_equal(auto_testpath, &path)
851+
852+
" Check a file can be found using environment variables
853+
let expanded_test_path = expand('$testdir/test.txt')
854+
call writefile(['testing...'], expanded_test_path)
855+
856+
" hinting an environment variable path
857+
call assert_equal(expanded_test_path, findfile('test.txt', $test_dir))
858+
859+
" using 'path' option with an environment variable
860+
set path=$testdir
861+
call assert_equal(expanded_test_path, findfile('test.txt'))
862+
863+
" using :find instead of findfile()
864+
find test.txt
865+
call assert_equal(expanded_test_path, expand('%:.'))
866+
enew
867+
endfunc
837868

838869
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ static char *(features[]) =
719719

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
1572,
722724
/**/
723725
1571,
724726
/**/

0 commit comments

Comments
 (0)