From 7b78ace466687071f2f167636da8fdf9bcdbd8ec Mon Sep 17 00:00:00 2001 From: David Ibia Date: Sun, 10 Mar 2024 12:20:39 +0100 Subject: [PATCH] style(remap.lua): improve code readability by adding comments and whitespace feat(remap.lua): add logic to only source specific file extensions to enhance security and prevent unintended sourcing of files --- lua/absolute/remap.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lua/absolute/remap.lua b/lua/absolute/remap.lua index 17103da..0bf606f 100644 --- a/lua/absolute/remap.lua +++ b/lua/absolute/remap.lua @@ -79,14 +79,24 @@ vim.keymap.set("n", "f", vim.lsp.buf.format, opts) opts.desc = "Regex Replace" vim.keymap.set("n", "sr", [[:%s/\<\>//gI]], opts) - opts.desc = "Replace selected text" vim.keymap.set("v", "ss", [[:s/\<\>//gI]], opts) -- Source File Keymap opts.desc = "Source File" vim.keymap.set("n", "", function() - vim.cmd("so") + -- Only source these file extensions + local allowed_extensions = [[".vim", ".lua", ".vimrc", ".gvimrc", ".nvim", ".nvimrc", ".sh"]] + + -- Get the file extension + local file_extension = vim.fn.expand("%:e") + + -- Check if the file extension is allowed + if string.find(allowed_extensions, file_extension) then + vim.cmd("so %") + else + print("Filetype not supported") + end end, opts) -- Manage VIM Maximizer