1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-11 03:27:05 +03:00

wezterm: fix panic when a large paste is chunked in an emoji

wezterm splits pastes into chunks of 1KB.  If that chunk was in
the middle of a UTF8 multibyte sequence, the rust string library
would panic.

This commit rounds the chunk size up to the next character
boundary.

closes: https://github.com/wez/wezterm/issues/281
This commit is contained in:
Wez Furlong 2020-09-27 09:38:34 -07:00
parent 9d33073d70
commit 1eab37b677

View File

@ -45,7 +45,13 @@ fn schedule_next_paste(paste: &Arc<Mutex<Paste>>) {
let pane = mux.get_pane(locked.pane_id).unwrap();
let remain = locked.text.len() - locked.offset;
let chunk = remain.min(PASTE_CHUNK_SIZE);
let mut chunk = remain.min(PASTE_CHUNK_SIZE);
// Make sure we chunk at a char boundary, otherwise the
// slice operation below will panic
while !locked.text.is_char_boundary(locked.offset + chunk) && chunk < remain {
chunk += 1;
}
let text_slice = &locked.text[locked.offset..locked.offset + chunk];
pane.send_paste(text_slice).unwrap();