fix (tags|btags): escape all special characters (#1806)

This commit is contained in:
ibhagwan
2022-03-26 02:29:34 -07:00
committed by GitHub
parent 40c1e88904
commit cf2d6d3428
2 changed files with 12 additions and 8 deletions

View File

@@ -431,10 +431,12 @@ files.tags = function(opts)
local selection = action_state.get_selected_entry()
if selection.scode then
local scode = string.gsub(selection.scode, "[$]$", "")
scode = string.gsub(scode, [[\\]], [[\]])
scode = string.gsub(scode, [[\/]], [[/]])
scode = string.gsub(scode, "[*]", [[\*]])
-- un-escape / then escape required
-- special chars for vim.fn.search()
-- ] ~ *
local scode = selection.scode:gsub([[\/]], "/"):gsub("[%]~*]", function(x)
return "\\" .. x
end)
vim.cmd "norm! gg"
vim.fn.search(scode)

View File

@@ -484,10 +484,12 @@ previewers.ctags = defaulter(function(_)
local determine_jump = function(entry)
if entry.scode then
return function(self)
local scode = string.gsub(entry.scode, "[$]$", "")
scode = string.gsub(scode, [[\\]], [[\]])
scode = string.gsub(scode, [[\/]], [[/]])
scode = string.gsub(scode, "[*]", [[\*]])
-- un-escape / then escape required
-- special chars for vim.fn.search()
-- ] ~ *
local scode = entry.scode:gsub([[\/]], "/"):gsub("[%]~*]", function(x)
return "\\" .. x
end)
pcall(vim.fn.matchdelete, self.state.hl_id, self.state.winid)
vim.cmd "norm! gg"