mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 13:21:38 +03:00
shlex: update usage to avoid warnings about NUL bytes
This commit is contained in:
parent
97f77f3d13
commit
a471618397
@ -1935,7 +1935,9 @@ impl DroppedFileQuoting {
|
||||
Self::None => s.to_string(),
|
||||
Self::SpacesOnly => s.replace(" ", "\\ "),
|
||||
// https://docs.rs/shlex/latest/shlex/fn.quote.html
|
||||
Self::Posix => shlex::quote(s).into_owned(),
|
||||
Self::Posix => shlex::try_quote(s)
|
||||
.unwrap_or_else(|_| "".into())
|
||||
.into_owned(),
|
||||
Self::Windows => {
|
||||
let chars_need_quoting = [' ', '\t', '\n', '\x0b', '\"'];
|
||||
if s.chars().any(|c| chars_need_quoting.contains(&c)) {
|
||||
|
@ -229,7 +229,7 @@ impl SpawnCommand {
|
||||
if let Some(label) = &self.label {
|
||||
Some(label.to_string())
|
||||
} else if let Some(args) = &self.args {
|
||||
Some(shlex::join(args.iter().map(|s| s.as_str())))
|
||||
Some(shlex::try_join(args.iter().map(|s| s.as_str())).ok()?)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -412,11 +412,13 @@ fn shell_split<'lua>(_: &'lua Lua, line: String) -> mlua::Result<Vec<String>> {
|
||||
}
|
||||
|
||||
fn shell_join_args<'lua>(_: &'lua Lua, args: Vec<String>) -> mlua::Result<String> {
|
||||
Ok(shlex::join(args.iter().map(|arg| arg.as_ref())))
|
||||
Ok(shlex::try_join(args.iter().map(|arg| arg.as_ref())).map_err(mlua::Error::external)?)
|
||||
}
|
||||
|
||||
fn shell_quote_arg<'lua>(_: &'lua Lua, arg: String) -> mlua::Result<String> {
|
||||
Ok(shlex::quote(&arg).into_owned())
|
||||
Ok(shlex::try_quote(&arg)
|
||||
.map_err(mlua::Error::external)?
|
||||
.into_owned())
|
||||
}
|
||||
|
||||
/// Returns the system hostname.
|
||||
|
@ -219,6 +219,16 @@ impl GuiFrontEnd {
|
||||
log::trace!("Got app event {event:?}");
|
||||
match event {
|
||||
ApplicationEvent::OpenCommandScript(file_name) => {
|
||||
let quoted_file_name = match shlex::try_quote(&file_name) {
|
||||
Ok(name) => name.to_owned().to_string(),
|
||||
Err(_) => {
|
||||
log::error!(
|
||||
"OpenCommandScript: {file_name} has embedded NUL bytes and
|
||||
cannot be launched via the shell"
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
promise::spawn::spawn(async move {
|
||||
use config::keyassignment::SpawnTabDomain;
|
||||
use wezterm_term::TerminalSize;
|
||||
@ -252,7 +262,7 @@ impl GuiFrontEnd {
|
||||
Ok((_tab, pane, _window_id)) => {
|
||||
log::trace!("Spawned {file_name} as pane_id {}", pane.pane_id());
|
||||
let mut writer = pane.writer();
|
||||
write!(writer, "{} ; exit\n", shlex::quote(&file_name)).ok();
|
||||
write!(writer, "{quoted_file_name} ; exit\n").ok();
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("Failed to spawn {file_name}: {err:#?}");
|
||||
|
Loading…
Reference in New Issue
Block a user