Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telescope find_files not escape file name properly #2315

Closed
darzok0914 opened this issue Jan 9, 2023 · 2 comments · Fixed by #2345
Closed

Telescope find_files not escape file name properly #2315

darzok0914 opened this issue Jan 9, 2023 · 2 comments · Fixed by #2345
Labels
bug Something isn't working

Comments

@darzok0914
Copy link

Description

Telescope find_files doesn't handle well file names containing specific regex like substrings.

Neovim version

NVIM v0.9.0-dev-583+gf62c30ad0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/Ben/neovim/neovim_repo/build/cmake.config -I/home/Ben/neovim/neovim_repo/src -I/home/Ben/neovim/neovim_repo/.deps/usr/include -I/usr/include -I/home/Ben/neovim/neovim_repo/build/src/nvim/auto -I/home/Ben/neovim/neovim_repo/build/include
Compiled by Ben@buildkitsandbox

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/home/Ben/neovim/build/share/nvim"

Run :checkhealth for more info

Operating system and version

macOs 12.6.2

Telescope version / branch / rev

04af51d

checkhealth telescope

==============================================================================
telescope: require("telescope.health").check()

Checking for required plugins ~
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies ~
- OK rg: found ripgrep 13.0.0
- OK fd: found fd 8.6.0

Steps to reproduce

Steps to reproduce

  1. Create a new file named:

[Ar-h] foo bar (cpp)"

  1. Run :Telescope find_files

Expected behavior

no error when cursor goes onto the file into the picker

Actual behavior

E5108: Error executing lua Vim:E944: Reverse range in character class
stack traceback:
[C]: in function 'expand'
....vim/plugged/telescope.nvim/lua/telescope/from_entry.lua:33: in function 'path'
...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:428: in function 'define_preview'
...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:388: in function 'preview'
...en/.vim/plugged/telescope.nvim/lua/telescope/pickers.lua:1075: in function 'refresh_previewer'
...en/.vim/plugged/telescope.nvim/lua/telescope/pickers.lua:1028: in function 'set_selection'
...en/.vim/plugged/telescope.nvim/lua/telescope/pickers.lua:792: in function 'move_selection'
...vim/plugged/telescope.nvim/lua/telescope/actions/set.lua:39: in function 'run_replace_or_original'
....vim/plugged/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'shift_selection'
...im/plugged/telescope.nvim/lua/telescope/actions/init.lua:81: in function 'run_replace_or_original'
....vim/plugged/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func'
...n/.vim/plugged/telescope.nvim/lua/telescope/mappings.lua:352: in function 'execute_keymap'
[string ":lua"]:1: in main chunk

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {
        'nvim-telescope/telescope.nvim',
        requires = {
          'nvim-lua/plenary.nvim',
          { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' },
        },
      },
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
  require('telescope').setup()
  require('telescope').load_extension('fzf')
  -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Telescope and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
@darzok0914 darzok0914 added the bug Something isn't working label Jan 9, 2023
@darzok0914
Copy link
Author

darzok0914 commented Jan 17, 2023

so I managed to fixed the issue by doing this change, it seems like everything else is working as well as expected so I don't think I broke anything, but obviously I don't really know the project well.

@Conni2461 do you have any comments or suggestions? I'm asking you because there is a TODO with your name on that file so you might have some comments

diff --git a/lua/telescope/from_entry.lua b/lua/telescope/from_entry.lua
index 486b57c..11c4792 100644
--- a/lua/telescope/from_entry.lua
+++ b/lua/telescope/from_entry.lua
@@ -30,7 +30,8 @@ function from_entry.path(entry, validate, escape)
     -- TODO(conni2461): we are not going to return the expanded path because
     --                  this would lead to cache misses in the perviewer.
     --                  Requires overall refactoring in previewer interface
-    local expanded = vim.fn.expand(path)
+    local escaped_path = vim.fn.escape(path, '?*[]')
+    local expanded = vim.fn.expand(escaped_path)
     if (vim.fn.filereadable(expanded) + vim.fn.isdirectory(expanded)) == 0 then
       return
     end

@Conni2461
Copy link
Member

just merged a fix, thanks to everyone for debugging :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants