fix(plugins): do not detach if using a slash in a session name (#3839)

This commit is contained in:
Aram Drevekenin 2024-12-06 09:37:57 +01:00 committed by GitHub
parent 581e8b73ee
commit a489b2166c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 17 deletions

View file

@ -462,6 +462,9 @@ impl State {
// through the package)
self.show_error("Session name must be shorter than 108 bytes");
return;
} else if self.new_session_info.name().contains('/') {
self.show_error("Session name cannot contain '/'");
return;
}
self.new_session_info.handle_selection(&self.session_name);
},
@ -483,6 +486,10 @@ impl State {
self.show_error("A resurrectable session by this name already exists.");
return; // s that we don't hide self
} else {
if renaming_session_name.contains('/') {
self.show_error("Session names cannot contain '/'");
return;
}
self.update_current_session_name_in_ui(&renaming_session_name);
rename_session(&renaming_session_name);
return; // s that we don't hide self

View file

@ -891,6 +891,16 @@ pub fn render_renaming_session_screen(
33 + new_session_name.width()..40 + new_session_name.width(),
);
print_text_with_coordinates(text, x, y, None, None);
if new_session_name.contains('/') {
let error_text = "Error: session name cannot contain '/'";
print_text_with_coordinates(
Text::new(error_text).color_range(3, ..),
x,
y + 2,
None,
None,
);
}
}
pub fn render_controls_line(

View file

@ -1142,21 +1142,29 @@ fn switch_session(
return Err(anyhow!("Failed to deserialize layout: {}", e));
}
}
let client_id = env.client_id;
let tab_position = tab_position.map(|p| p + 1); // ¯\_()_/¯
let connect_to_session = ConnectToSession {
name: session_name,
tab_position,
pane_id,
layout,
cwd,
};
env.senders
.send_to_server(ServerInstruction::SwitchSession(
connect_to_session,
client_id,
))
.with_context(err_context)?;
if session_name
.as_ref()
.map(|s| s.contains('/'))
.unwrap_or(false)
{
log::error!("Session names cannot contain \'/\'");
} else {
let client_id = env.client_id;
let tab_position = tab_position.map(|p| p + 1); // ¯\_()_/¯
let connect_to_session = ConnectToSession {
name: session_name,
tab_position,
pane_id,
layout,
cwd,
};
env.senders
.send_to_server(ServerInstruction::SwitchSession(
connect_to_session,
client_id,
))
.with_context(err_context)?;
}
Ok(())
}
@ -1437,8 +1445,12 @@ fn rename_tab(env: &PluginEnv, tab_index: u32, new_name: &str) {
fn rename_session(env: &PluginEnv, new_session_name: String) {
let error_msg = || format!("failed to rename session in plugin {}", env.name());
let action = Action::RenameSession(new_session_name);
apply_action!(action, error_msg, env);
if new_session_name.contains('/') {
log::error!("Session names cannot contain \'/\'");
} else {
let action = Action::RenameSession(new_session_name);
apply_action!(action, error_msg, env);
}
}
fn disconnect_other_clients(env: &PluginEnv) {