quote_path: also quote ampersands (#6846)

pull/6815/head
Lukas Neubert 2020-11-16 18:26:44 +01:00 committed by GitHub
parent d633261a99
commit dbdcef5166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -113,7 +113,7 @@ fn main() {
for file in files { for file in files {
fpath := os.real_path(file) fpath := os.real_path(file)
mut worker_command_array := cli_args_no_files.clone() mut worker_command_array := cli_args_no_files.clone()
worker_command_array << ['-worker', util.quote_path_with_spaces(fpath)] worker_command_array << ['-worker', util.quote_path(fpath)]
worker_cmd := worker_command_array.join(' ') worker_cmd := worker_command_array.join(' ')
if foptions.is_verbose { if foptions.is_verbose {
eprintln('vfmt worker_cmd: $worker_cmd') eprintln('vfmt worker_cmd: $worker_cmd')

View File

@ -126,7 +126,7 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) {
vexe := pref.vexe_path() vexe := pref.vexe_path()
vroot := os.dir(vexe) vroot := os.dir(vexe)
set_vroot_folder(vroot) set_vroot_folder(vroot)
tool_args := args_quote_paths_with_spaces(args) tool_args := args_quote_paths(args)
tool_basename := os.real_path(os.join_path(vroot, 'cmd', 'tools', tool_name)) tool_basename := os.real_path(os.join_path(vroot, 'cmd', 'tools', tool_name))
tool_exe := path_of_executable(tool_basename) tool_exe := path_of_executable(tool_basename)
tool_source := tool_basename + '.v' tool_source := tool_basename + '.v'
@ -200,17 +200,21 @@ pub fn should_recompile_tool(vexe string, tool_source string) bool {
return should_compile return should_compile
} }
pub fn quote_path_with_spaces(s string) string { pub fn quote_path(s string) string {
if s.contains(' ') { mut qs := s
return '"$s"' if qs.contains('&') {
qs = qs.replace('&', '\\&')
} }
return s if qs.contains(' ') {
return '"$qs"'
}
return qs
} }
pub fn args_quote_paths_with_spaces(args []string) string { pub fn args_quote_paths(args []string) string {
mut res := []string{} mut res := []string{}
for a in args { for a in args {
res << quote_path_with_spaces(a) res << quote_path(a)
} }
return res.join(' ') return res.join(' ')
} }