Skip to content

Commit e100f40

Browse files
DenzellceWolf
authored andcommitted
fix(executer): shell quote arguments
1 parent 2969b80 commit e100f40

6 files changed

Lines changed: 20 additions & 25 deletions

File tree

lua/cmake-tools/init.lua

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ function cmake.generate(opt, callback)
257257

258258
local args = {
259259
"-B",
260-
utils.transform_path(config:build_directory_path(), config.executor.name == "quickfix"),
260+
config:build_directory_path(),
261261
"-S",
262262
".",
263263
}
@@ -298,9 +298,7 @@ function cmake.clean(callback)
298298
return
299299
end
300300

301-
local path = Path:new(
302-
utils.transform_path(config:build_directory_path(), config.executor.name == "quickfix")
303-
)
301+
local path = Path:new(config:build_directory_path())
304302
if not (path / "CMakeCache.txt"):exists() then
305303
-- no need to clean up as we do not have a cache
306304
return
@@ -407,7 +405,7 @@ function cmake.build(opt, callback)
407405
else
408406
args = {
409407
"--build",
410-
utils.transform_path(config:build_directory_path(), config.executor.name == "quickfix"),
408+
config:build_directory_path(),
411409
}
412410
end
413411

lua/cmake-tools/terminal.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,14 @@ function _terminal.run(cmd, env_script, env, args, cwd, opts, on_exit, on_output
602602
if osys.iswin32 and not is_windows_shell() then
603603
cwd = cwd:gsub("\\", "/")
604604
end
605-
cwd = utils.transform_path(cwd)
605+
cwd = utils.shell_quote(cwd)
606606
local envTbl = {}
607607
local fmtStr = osys.iswin32 and "set %s=%s" or "%s=%s"
608608
for k, v in pairs(env) do
609609
table.insert(envTbl, string.format(fmtStr, k, v))
610610
end
611611
env = table.concat(envTbl, " ")
612-
args = table.concat(args, " ")
612+
args = table.concat(vim.tbl_map(utils.shell_quote, args), " ")
613613

614614
return cmd, env, args, cwd
615615
end

lua/cmake-tools/test/ctest.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function ctest.run(ctest_command, env, config, opt)
7777
if opt.preset then
7878
vim.list_extend(args, { "--preset", opt.preset })
7979
else
80-
vim.list_extend(args, { "--test-dir", utils.transform_path(opt.build_dir) })
80+
vim.list_extend(args, { "--test-dir", opt.build_dir })
8181
end
8282

8383
if opt.label then

lua/cmake-tools/toggleterm.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function _toggleterm.run(cmd, env_script, env, args, cwd, opts, on_exit, on_outp
2828
local full_cmd = ""
2929

3030
-- Launch form executable's build directory by default
31-
full_cmd = "cd " .. utils.transform_path(cwd) .. " &&"
31+
full_cmd = "cd " .. utils.shell_quote(cwd) .. " &&"
3232

3333
if osys.iswin32 then
3434
for k, v in pairs(env) do
@@ -40,15 +40,15 @@ function _toggleterm.run(cmd, env_script, env, args, cwd, opts, on_exit, on_outp
4040
end
4141
end
4242

43-
full_cmd = full_cmd .. " " .. utils.transform_path(cmd)
43+
full_cmd = full_cmd .. " " .. utils.shell_quote(cmd)
4444

4545
if osys.islinux or osys.iswsl or osys.ismac then
4646
full_cmd = " " .. full_cmd -- adding a space in front of the command prevents bash from recording the command in the history (if configured)
4747
end
4848

4949
-- Add args to the cmd
5050
for _, arg in ipairs(args) do
51-
full_cmd = full_cmd .. " " .. arg
51+
full_cmd = full_cmd .. " " .. utils.shell_quote(arg)
5252
end
5353

5454
_toggleterm.cmd = full_cmd

lua/cmake-tools/utils.lua

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ function utils.copyfile(src, target)
8888
-- if we don't always use terminal
8989
local cmd = "exec "
9090
.. "'!cmake -E copy "
91-
.. utils.transform_path(src)
91+
.. utils.shell_quote(src)
9292
.. " "
93-
.. utils.transform_path(target)
93+
.. utils.shell_quote(target)
9494
.. "'"
9595
vim.cmd(cmd)
9696
end
@@ -101,22 +101,19 @@ function utils.softlink(src, target)
101101
-- if we don't always use terminal
102102
local cmd = "exec "
103103
.. "'!cmake -E create_symlink "
104-
.. utils.transform_path(src)
104+
.. utils.shell_quote(src)
105105
.. " "
106-
.. utils.transform_path(target)
106+
.. utils.shell_quote(target)
107107
.. "'"
108108
vim.cmd(cmd)
109109
end
110110
end
111111

112-
function utils.transform_path(path, keep)
113-
if keep then
114-
return path
115-
end
116-
if path[1] ~= '"' and string.find(path, " ") then
117-
return '"' .. path .. '"'
112+
function utils.shell_quote(str)
113+
if str[1] ~= '"' and string.find(str, " ") then
114+
return '"' .. str .. '"'
118115
else
119-
return path
116+
return str
120117
end
121118
end
122119

lua/cmake-tools/vimux.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function _vimux.prepare_cmd_for_run(cmd, env, args, cwd)
4343
local full_cmd = ""
4444

4545
-- Launch form executable's build directory by default
46-
full_cmd = "cd " .. utils.transform_path(cwd) .. " &&"
46+
full_cmd = "cd " .. utils.shell_quote(cwd) .. " &&"
4747

4848
if osys.iswin32 then
4949
for k, v in pairs(env) do
@@ -55,15 +55,15 @@ function _vimux.prepare_cmd_for_run(cmd, env, args, cwd)
5555
end
5656
end
5757

58-
full_cmd = full_cmd .. " " .. utils.transform_path(cmd)
58+
full_cmd = full_cmd .. " " .. utils.shell_quote(cmd)
5959

6060
if osys.islinux or osys.iswsl or osys.ismac then
6161
full_cmd = " " .. full_cmd -- adding a space in front of the command prevents bash from recording the command in the history (if configured)
6262
end
6363

6464
-- Add args to the cmd
6565
for _, arg in ipairs(args) do
66-
full_cmd = full_cmd .. " " .. arg
66+
full_cmd = full_cmd .. " " .. utils.shell_quote(arg)
6767
end
6868

6969
if osys.iswin32 then -- wrap in sub process to prevent env vars from being persited

0 commit comments

Comments
 (0)