feat: accept only printable unicode char (#1016)

* feat: accept only printable unicode char

* chore: revert comments
This commit is contained in:
Jae-Heon Ji 2022-01-25 22:11:31 +09:00 committed by GitHub
parent 430fd58707
commit 8d224cb84a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

@ -611,13 +611,16 @@ impl Screen {
active_tab.name = String::new(); active_tab.name = String::new();
} }
"\u{007F}" | "\u{0008}" => { "\u{007F}" | "\u{0008}" => {
//delete and backspace keys // delete and backspace keys
active_tab.name.pop(); active_tab.name.pop();
} }
c => { c => {
// It only allows printable unicode
if buf.iter().all(|u| matches!(u, 0x20..=0x7E)) {
active_tab.name.push_str(c); active_tab.name.push_str(c);
} }
} }
}
self.update_tabs(); self.update_tabs();
} }
pub fn change_mode(&mut self, mode_info: ModeInfo, client_id: ClientId) { pub fn change_mode(&mut self, mode_info: ModeInfo, client_id: ClientId) {

View file

@ -1998,14 +1998,19 @@ impl Tab {
pub fn update_active_pane_name(&mut self, buf: Vec<u8>, client_id: ClientId) { 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) { if let Some(active_terminal_id) = self.get_active_terminal_id(client_id) {
let s = str::from_utf8(&buf).unwrap();
let active_terminal = self let active_terminal = self
.panes .panes
.get_mut(&PaneId::Terminal(active_terminal_id)) .get_mut(&PaneId::Terminal(active_terminal_id))
.unwrap(); .unwrap();
// 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); active_terminal.update_name(s);
} }
} }
}
pub fn is_position_inside_viewport(&self, point: &Position) -> bool { pub fn is_position_inside_viewport(&self, point: &Position) -> bool {
let Position { let Position {