From febee7b85f030dfe6e08fa35728e6bec3202692b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDinesh?= <“reachtodinesh@gmail.com”> Date: Fri, 22 Jul 2022 07:10:19 +0530 Subject: [PATCH 1/3] fix: Add backslash when filepath contains spaces --- src/cmd_line.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cmd_line.rs b/src/cmd_line.rs index c91ac00..c350d79 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -170,7 +170,12 @@ pub fn handle_command_line_arguments(args: Vec) -> Result<(), String> { neovim_args.push("-p".to_owned()); } - neovim_args.extend::>(files_to_open); + neovim_args.extend::>( + files_to_open + .iter() + .map(|file| file.replace(" ", "\\ ")) + .collect(), + ); /* * Integrate Environment Variables as Defaults to the command-line ones. From 83edde81034649e7ee2c4e54855a5840a5a2e340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDinesh?= <“reachtodinesh@gmail.com”> Date: Fri, 22 Jul 2022 08:57:59 +0530 Subject: [PATCH 2/3] macos specific filename with space check --- src/cmd_line.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cmd_line.rs b/src/cmd_line.rs index c350d79..6b94c39 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -170,12 +170,17 @@ pub fn handle_command_line_arguments(args: Vec) -> Result<(), String> { neovim_args.push("-p".to_owned()); } - neovim_args.extend::>( - files_to_open - .iter() - .map(|file| file.replace(" ", "\\ ")) - .collect(), - ); + if cfg!(target_os = "macos") { + // escape filepath which contain spaces + neovim_args.extend::>( + files_to_open + .iter() + .map(|file| file.replace(" ", "\\ ")) + .collect(), + ); + } else { + neovim_args.extend::>(files_to_open); + } /* * Integrate Environment Variables as Defaults to the command-line ones. From 148e9e450fc53e8153a594ce241a387fa7d25b46 Mon Sep 17 00:00:00 2001 From: MultisampledNight Date: Fri, 22 Jul 2022 09:05:55 +0200 Subject: [PATCH 3/3] Switch to shlex to make filenames shellsafe shlex also takes care of any other POSIX-shell specific stuff, such as ". Also cleans up the vector extension a bit. --- Cargo.lock | 1 + Cargo.toml | 1 + src/cmd_line.rs | 5 ++--- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b7bff9..0ba35bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1367,6 +1367,7 @@ dependencies = [ "rmpv", "serde", "serde_json", + "shlex", "skia-safe", "swash", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 6a52df7..ffb315f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ rand = "0.8.5" rmpv = "1.0.0" serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" +shlex = "1.1.0" swash = "0.1.4" tokio = { version = "1.17.0", features = ["full"] } tokio-util = { version = "0.7.1", features = ["compat"] } diff --git a/src/cmd_line.rs b/src/cmd_line.rs index 6b94c39..4882b32 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -172,11 +172,10 @@ pub fn handle_command_line_arguments(args: Vec) -> Result<(), String> { if cfg!(target_os = "macos") { // escape filepath which contain spaces - neovim_args.extend::>( + neovim_args.extend( files_to_open .iter() - .map(|file| file.replace(" ", "\\ ")) - .collect(), + .map(|file| shlex::quote(file).into_owned()), ); } else { neovim_args.extend::>(files_to_open);