From 755abbc8d5101b1ea79291635a91896fd752e8ef Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 3 Aug 2026 15:35:30 -0500 Subject: [PATCH] fix(zip): only refuse a cwd unzip on Windows --- runtime/lua/nvim/zip.lua | 8 ++++++-- test/functional/plugin/zip_spec.lua | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/runtime/lua/nvim/zip.lua b/runtime/lua/nvim/zip.lua index 32eb97476c..50a96960c1 100644 --- a/runtime/lua/nvim/zip.lua +++ b/runtime/lua/nvim/zip.lua @@ -12,8 +12,12 @@ local function unzip() end -- Windows searches the current directory before $PATH, so an archive could be opened with an -- `unzip` shipped next to it. - if vim.fs.dirname(vim.fs.normalize(command)) == vim.fs.normalize(vim.fn.getcwd()) then - return nil, 'refusing to run unzip from the current directory' + if vim.fn.has('win32') == 1 then + local dir = uv.fs_realpath(vim.fs.dirname(vim.fs.normalize(command))) + local cwd = uv.fs_realpath(vim.fn.getcwd()) + if dir and cwd and dir == cwd then + return nil, 'refusing to run unzip from the current directory' + end end return command end diff --git a/test/functional/plugin/zip_spec.lua b/test/functional/plugin/zip_spec.lua index e8ce394e8f..088f2441b6 100644 --- a/test/functional/plugin/zip_spec.lua +++ b/test/functional/plugin/zip_spec.lua @@ -330,6 +330,19 @@ describe('nvim.zip', function() end end) + it('runs the backend when the cwd is its directory', function() + t.skip(t.is_os('win'), 'N/A: Windows searches the cwd before $PATH') + local archive = stage(fixtures, 'browser.zip') + local bin = vim.fs.joinpath(assert(vim.uv.fs_realpath(root)), 'bin') + t.mkdir(bin) + assert(vim.uv.fs_symlink(vim.fn.exepath('unzip'), vim.fs.joinpath(bin, 'unzip'))) + n.clear({ args = { '--clean' }, env = { PATH = bin .. ':' .. os.getenv('PATH') } }) + + api.nvim_set_current_dir(bin) + edit(archive) + eq('folder/', lines()[1]) + end) + it('keeps a leading dash in a path from becoming a backend option', function() local archive = stage(old_samples, 'poc.zip') clear_zip()