justinmk / vim-dirvish

Directory viewer for Vim :zap:
Other
1.18k stars 64 forks source link

Dirvish gets confused inside folders containing "$" #182

Closed wincent closed 4 years ago

wincent commented 4 years ago

To reproduce

mkdir 'x$y'
touch 'x$y/z'
vim 'x$y/z'

Then hit - to bring up Dirvish.

Expected result

Actual result

If you hit - again, you will see the directory that contains the problem folder, and x$y/ is present in the list.

Observations

Problem is that the glob() call here is returning an empty list.

ie. If I backslash-escape the $ then everything works fine. In other words, an fnameescape() would fix this, but that might also escape too much. 🤷‍♂️

I'm testing this locally, but like I said, it may be too aggressive:

diff --git a/autoload/dirvish.vim b/autoload/dirvish.vim
index 4fd26a2..9c65b26 100644
--- a/autoload/dirvish.vim
+++ b/autoload/dirvish.vim
@@ -53,7 +53,7 @@ endif

 function! s:list_dir(dir) abort
   " Escape for glob().
-  let dir_esc = escape(substitute(a:dir,'\[','[[]','g'),'{}')
+  let dir_esc = fnameescape(escape(substitute(a:dir,'\[','[[]','g'),'{}'))
   let paths = s:globlist(dir_esc.'*')
   "Append dot-prefixed files. glob() cannot do both in 1 pass.
   let paths = paths + s:globlist(dir_esc.'.[^.]*')
justinmk commented 4 years ago

Thanks for debugging this! Does this patch work instead?

diff --git a/autoload/dirvish.vim b/autoload/dirvish.vim
index 4fd26a2..9c65b26 100644
--- a/autoload/dirvish.vim
+++ b/autoload/dirvish.vim
@@ -53,7 +53,7 @@ endif

 function! s:list_dir(dir) abort
   " Escape for glob().
-  let dir_esc = escape(substitute(a:dir,'\[','[[]','g'),'{}')
+  let dir_esc = escape(substitute(a:dir,'\[','[[]','g'),'{}$')
   let paths = s:globlist(dir_esc.'*')
   "Append dot-prefixed files. glob() cannot do both in 1 pass.
   let paths = paths + s:globlist(dir_esc.'.[^.]*')

related: https://github.com/justinmk/vim-dirvish/pull/184 , https://github.com/justinmk/vim-dirvish/pull/190

wincent commented 4 years ago

Yep, that works @justinmk. Both for the synthetic test case that I listed in the summary and the real-world scenario where I originally ran into this.