Error opening directory with deep directory stucture and many underscores in the path name
kting28 opened this issue · comments
Kai Ting commented
Description
opening a deep directory tree with many underscores in path name crashes with:
Error executing Lua callback: ...kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree/utils.lua:62: too many captures
stack traceback:
[C]: in function 'gsub'
...kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree/utils.lua:62: in function 'path_relative'
...plugged/nvim-tree.lua/lua/nvim-tree/explorer/filters.lua:76: in function 'custom'
...plugged/nvim-tree.lua/lua/nvim-tree/explorer/filters.lua:127: in function 'should_filter'
...plugged/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:33: in function 'populate_children'
...plugged/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:68: in function 'explore'
...im/plugged/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:28: in function '_load'
...im/plugged/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:21: in function 'new'
.../kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree/core.lua:18: in function 'init'
...2/kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree/lib.lua:161: in function 'open'
/usr2/kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree.lua:181: in function 'open'
Neovim version
NVIM v0.8.3
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Operating system and version
Ubuntu 20
nvim-tree version
Minimal config
Any config that enables nvim-tree is fine
Steps to reproduce
Looks like more than 32 levels triggers it
1. mkdir -p _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_
2. cd _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_
3. touch test.txt
4. nvim
5. :NvimTreeOpen
Expected behavior
Directory opens
Actual behavior
crashes. added some prints in path_relative
relative_to: /home/kting/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_
path: /home/kting/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/test.txt
matching_str /home/kting/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/(%_)/
34
final:
Error executing Lua callback: ...kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree/utils.lua:66: too many captures
stack traceback:
[C]: in function 'gsub'
...kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree/utils.lua:66: in function 'path_relative'
...plugged/nvim-tree.lua/lua/nvim-tree/explorer/filters.lua:76: in function 'custom'
...plugged/nvim-tree.lua/lua/nvim-tree/explorer/filters.lua:127: in function 'should_filter'
...plugged/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:33: in function 'populate_children'
...plugged/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:68: in function 'explore'
...im/plugged/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:28: in function '_load'
...im/plugged/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:21: in function 'new'
.../kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree/core.lua:18: in function 'init'
...e/kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree/lib.lua:161: in function 'open'
/home/kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree.lua:181: in function 'open'
/home/kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree.lua:360: in function </home/kting/.vim/plugged/nvim-tree.lua/lua/nvim-tree.lua:359>
Kai Ting commented
Perhaps path_to_matching_str
doesn't need to capture the substitutions?
function M.path_to_matching_str(path)
return path:gsub("(%-)", "(%%-)"):gsub("(%.)", "(%%.)"):gsub("(%_)", "(%%_)")
end
Should it be ?
function M.path_to_matching_str(path)
return path:gsub("(%-)", "%%-"):gsub("(%.)", "%%."):gsub("(%_)", "%%_")
end
This fixes the issue for me