diff --git a/docs/changelog.md b/docs/changelog.md index 7e54a77d9..4bf39326f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -13,6 +13,7 @@ As features stabilize some brief notes about them will accumulate here. * Fixed: ssh client would read `/etc/ssh/config` rather than the proper `/etc/ssh/ssh_config` * x11: support for [VoidSymbol](config/keys.md#voidsymbol) in key assignments. Thanks to [@digitallyserviced](https://github.com/digitallyserviced)! [#759](https://github.com/wez/wezterm/pull/759) +* Fixed: UTF8-encoded-C1 control codes were not always recognized as control codes, and could result in a panic when later attempting to update the line. [#768](https://github.com/wez/wezterm/issues/768) ### 20210502-154244-3f7122cb diff --git a/term/src/test/mod.rs b/term/src/test/mod.rs index 1b924e945..7df1b4c66 100644 --- a/term/src/test/mod.rs +++ b/term/src/test/mod.rs @@ -789,6 +789,13 @@ fn test_scrollup() { assert_eq!(term.screen().visible_row_to_stable_row(0), 7); } +#[test] +fn test_ri() { + let mut term = TestTerm::new(3, 1, 10); + term.print("1\n\u{8d}\n"); + assert_all_contents(&term, file!(), line!(), &["1", "", ""]); +} + #[test] fn test_scroll_margins() { let mut term = TestTerm::new(3, 1, 10); diff --git a/termwiz/src/surface/line.rs b/termwiz/src/surface/line.rs index a0c0b039e..3076309de 100644 --- a/termwiz/src/surface/line.rs +++ b/termwiz/src/surface/line.rs @@ -305,9 +305,15 @@ impl Line { pub fn set_cell(&mut self, idx: usize, cell: Cell) -> &Cell { let width = cell.width(); - // if the line isn't wide enough, pad it out with the default attributes - if idx + width >= self.cells.len() { - self.cells.resize(idx + width, Cell::default()); + // if the line isn't wide enough, pad it out with the default attributes. + // The .max(1) stuff is here in case we get called with a + // zero-width cell. That shouldn't happen: those sequences + // should get filtered out in the terminal parsing layer, + // but in case one does sneak through, we need to ensure that + // we grow the cells array to hold this bogus entry. + // https://github.com/wez/wezterm/issues/768 + if idx + width.max(1) >= self.cells.len() { + self.cells.resize(idx + width.max(1), Cell::default()); } self.invalidate_implicit_hyperlinks(); diff --git a/vtparse/src/lib.rs b/vtparse/src/lib.rs index 9c62c0922..cb0a02df5 100644 --- a/vtparse/src/lib.rs +++ b/vtparse/src/lib.rs @@ -622,7 +622,9 @@ impl VTParser { let byte = ((c as u32) & 0xff) as u8; let (action, state) = lookup(self.utf8_return_state, byte); - if state != self.utf8_return_state && state != State::Utf8Sequence { + if action == Action::Execute + || (state != self.utf8_return_state && state != State::Utf8Sequence) + { self.action(lookup_exit(self.utf8_return_state), 0, actor); self.action(action, byte, actor); self.action(lookup_entry(state), 0, actor); @@ -941,6 +943,14 @@ mod test { ); } + #[test] + fn utf8_control() { + assert_eq!( + parse_as_vec("\u{8d}".as_bytes()), + vec![VTAction::ExecuteC0orC1(0x8d)] + ); + } + #[test] fn tmux_control() { assert_eq!(