From b98b9a93c67cb999493ccdc602e711c8a7a98d64 Mon Sep 17 00:00:00 2001 From: Reed Koser Date: Thu, 30 Jun 2022 03:09:36 -0700 Subject: [PATCH] fix: grep_string crashes when string has newline (#2026) Fixes the crash below by sanitizing the title to not include the linebreak (replacing it by a "\n" string) stack traceback: [C]: in function 'nvim_buf_set_lines' .../nvim/plugged/plenary.nvim/lua/plenary/window/border.lua:222: in function '__align_calc_config' .../nvim/plugged/plenary.nvim/lua/plenary/window/border.lua:266: in function 'new' ...are/nvim/plugged/plenary.nvim/lua/plenary/popup/init.lua:384: in function 'create' ...re/nvim/plugged/telescope.nvim/lua/telescope/pickers.lua:326: in function '_create_window' ...re/nvim/plugged/telescope.nvim/lua/telescope/pickers.lua:399: in function 'find' ...m/plugged/telescope.nvim/lua/telescope/builtin/files.lua:151: in function 'v' ...m/plugged/telescope.nvim/lua/telescope/builtin/files.lua:475: in function 'v' ...im/plugged/telescope.nvim/lua/telescope/builtin/init.lua:487: in function 'grep_string' Fixes #2023 --- lua/telescope/builtin/files.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index 2dd11c7..3d4b1bf 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -124,6 +124,8 @@ files.grep_string = function(opts) local word_match = opts.word_match opts.entry_maker = opts.entry_maker or make_entry.gen_from_vimgrep(opts) + local title_word = word:gsub("\n", "\\n") + local additional_args = {} if opts.additional_args ~= nil and type(opts.additional_args) == "function" then additional_args = opts.additional_args(opts) @@ -144,7 +146,7 @@ files.grep_string = function(opts) end pickers.new(opts, { - prompt_title = "Find Word (" .. word .. ")", + prompt_title = "Find Word (" .. title_word .. ")", finder = finders.new_oneshot_job(args, opts), previewer = conf.grep_previewer(opts), sorter = conf.generic_sorter(opts),