From a8ac4dee48fa6289bbddf18517bf06169da58c2a Mon Sep 17 00:00:00 2001 From: Lv Sihan <143868321+Pokryton@users.noreply.github.com> Date: Sun, 15 Oct 2023 01:47:45 +0800 Subject: [PATCH] Escape metacharacters when loading file into cmdline (#196) * Escape metacharacters when loading file into cmdline * format: apply stylua --------- Co-authored-by: Steven Arcangeli --- lua/oil/actions.lua | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lua/oil/actions.lua b/lua/oil/actions.lua index e810ba6d..d446a0b5 100644 --- a/lua/oil/actions.lua +++ b/lua/oil/actions.lua @@ -224,14 +224,10 @@ M.refresh = { end, } -local function open_cmdline_with_args(args) - local escaped = vim.api.nvim_replace_termcodes( - ": " .. args .. string.rep("", args:len() + 1), - true, - false, - true - ) - vim.api.nvim_feedkeys(escaped, "n", true) +local function open_cmdline_with_path(path) + local escaped = + vim.api.nvim_replace_termcodes(": " .. vim.fn.fnameescape(path) .. "", true, false, true) + vim.api.nvim_feedkeys(escaped, "n", false) end M.open_cmdline = { @@ -253,7 +249,7 @@ M.open_cmdline = { return end local fullpath = fs.shorten_path(fs.posix_to_os_path(path) .. entry.name) - open_cmdline_with_args(fullpath) + open_cmdline_with_path(fullpath) end, } @@ -275,7 +271,7 @@ M.open_cmdline_dir = { local fs = require("oil.fs") local dir = oil.get_current_dir() if dir then - open_cmdline_with_args(fs.shorten_path(dir)) + open_cmdline_with_path(fs.shorten_path(dir)) end end, }