Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: accept only printable unicode char #1016

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,14 @@ impl Screen {
active_tab.name = String::new();
}
"\u{007F}" | "\u{0008}" => {
//delete and backspace keys
// delete and backspace keys
active_tab.name.pop();
}
c => {
active_tab.name.push_str(c);
// It only allows printable unicode
if buf.iter().all(|u| matches!(u, 0x20..=0x7E)) {
active_tab.name.push_str(c);
}
}
}
self.update_tabs();
Expand Down
9 changes: 7 additions & 2 deletions zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1998,12 +1998,17 @@ impl Tab {

pub fn update_active_pane_name(&mut self, buf: Vec<u8>, client_id: ClientId) {
if let Some(active_terminal_id) = self.get_active_terminal_id(client_id) {
let s = str::from_utf8(&buf).unwrap();
let active_terminal = self
.panes
.get_mut(&PaneId::Terminal(active_terminal_id))
.unwrap();
active_terminal.update_name(s);

// It only allows printable unicode, delete and backspace keys.
let is_updatable = buf.iter().all(|u| matches!(u, 0x20..=0x7E | 0x08 | 0x7F));
if is_updatable {
let s = str::from_utf8(&buf).unwrap();
active_terminal.update_name(s);
}
}
}

Expand Down