Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: shell escape single quote #281

Closed
AbaoFromCUG opened this issue Apr 8, 2024 · 2 comments · Fixed by #308
Closed

bug: shell escape single quote #281

AbaoFromCUG opened this issue Apr 8, 2024 · 2 comments · Fixed by #308
Labels
bug Something isn't working

Comments

@AbaoFromCUG
Copy link

Neovim version (nvim -v)

NVIM v0.10.0-dev

Operating system/version

Linux

Describe the bug

Issue

I am using overseer.nvim+toggleterm.nvim+neotest+neotest-plenary, and writing test for my neovim plugin.

I write xxx_spec.lua and run it via :lua require("neotest").run.run(vim.fn.expand("%")) but failed with error zsh: parse error near `)' , here is the output of toggleterm terminal window

$ /usr/bin/nvim --headless -i NONE -n --noplugin --cmd 'lua vim.opt.runtimepath:prepend(\'/home/abao/.local/share/nvim/lazy/plenary.nvim\')' --cmd 'lua package.path = \'lua/?.lua;\' .. \'lua/?/init.lua;\' .. package.path' -u tests/minimal_init.lua -c 'source /home/abao/.local/share/nvim/lazy/neotest-plenary/run_tests.lua' -c 'lua _run_tests({results = \'/tmp/nvim.abao/9WCB57/3\', file = \'/home/abao/Documents/plugins/websocket.nvim/tests/websocket/websocket_spec.lua\', filter = {}})'
zsh: parse error near `)'
$ exit $?

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

  1. nvim -u repro.lua xxx_spec.lua
  2. :lua require("neotest").run.run(vim.fn.expand("%"))

Expected Behavior

I guess this is a issue of escaping a single quoted string. There is a question in stackoverflow https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings

Here are two solutions:

Support escape single quoted

Should we add a test case in tests/shell_spec.lua?

      it("Escape a single quoted string", function()
        local got = shell.escape_cmd({ "foo", "baz 'qux'" }, "strong")
        assert.equals("?", got)
      end)

Change escape method to weak (double quote)

or change shell.escape_cmd method of lua/overseer/strategy/toggleterm.lua to weak to avoid this issue

if type(cmd) == "table" then
cmd = shell.escape_cmd(cmd, "strong")
end

Minimal example file

-- xxx_spec.lua
describe("test", function()
	it("code", function() end)
end)

Minimal init.lua

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	"folke/tokyonight.nvim",
	{ "stevearc/dressing.nvim", config = true },
	{
		"stevearc/overseer.nvim",
		config = function()
			require("overseer").setup({
				-- add your overseer config here
			})
		end,
	},
	-- add any other plugins here
	{
		"stevearc/overseer.nvim",
		config = function()
			require("overseer").setup({
				templates = { "builtin" },
				strategy = {
					"toggleterm",
					direction = "float",
                    shell="bash",
					use_shell = true,
				},
			})
		end,
	},
	{
		"nvim-neotest/neotest",
		dependencies = {
			"nvim-neotest/nvim-nio",
			"nvim-lua/plenary.nvim",
			"nvim-treesitter/nvim-treesitter",
		},
		config = function()
			require("neotest").setup({
				adapters = {
					require("neotest-plenary"),
				},
				consumers = {
					overseer = require("neotest.consumers.overseer"),
				},
			})
		end,
	},
    { "akinsho/toggleterm.nvim", opts = {} },
	"nvim-neotest/neotest-plenary",
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Additional context

Thanks

@AbaoFromCUG AbaoFromCUG added the bug Something isn't working label Apr 8, 2024
@stevearc
Copy link
Owner

stevearc commented Jun 6, 2024

Can you give #308 a try and see if it fixes your issue?

@stevearc stevearc added the question Further information is requested label Jun 6, 2024
@AbaoFromCUG
Copy link
Author

Yes, I just tried and your commit fixed my issue, I finally don't need to use my local trick modification anymore.

thanks.

@github-actions github-actions bot removed the question Further information is requested label Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants