diff options
author | DaftMouse <daftmouse@protonmail.com> | 2022-01-20 20:57:58 -0300 |
---|---|---|
committer | Kirill Chibisov <contact@kchibisov.com> | 2022-02-10 03:17:21 +0300 |
commit | 72f8d0ed6c848ba6e438856b8ef749534f590c38 (patch) | |
tree | 6dbc0c9bdac427482e92262668cbcad29ab5145f | |
parent | 54f74caf857703247b8f2c5a2aaddf169ea2cb6d (diff) | |
download | alacritty-72f8d0ed6c848ba6e438856b8ef749534f590c38.tar.gz alacritty-72f8d0ed6c848ba6e438856b8ef749534f590c38.zip |
Fix OSC 104 with empty second parameter
This fixes a bug where using OSC 104 without parameters but
with a trailling semicolon (e.g. '\e]104;\e\\') would not be handled.
Fixes #5542.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | alacritty_terminal/src/ansi.rs | 52 |
2 files changed, 52 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 091044f8..6f293d74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - OSC 4 not handling `?` - `?` in OSC strings reporting default colors instead of modified ones +- OSC 104 not clearing colors when second parameter is empty ## 0.10.0 diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs index 869d051b..06ea0234 100644 --- a/alacritty_terminal/src/ansi.rs +++ b/alacritty_terminal/src/ansi.rs @@ -1064,7 +1064,7 @@ where // Reset color index. b"104" => { // Reset all color indexes when no parameters are given. - if params.len() == 1 { + if params.len() == 1 || params[1].is_empty() { for i in 0..256 { self.handler.reset_color(i); } @@ -1506,6 +1506,7 @@ mod tests { attr: Option<Attr>, identity_reported: bool, color: Option<Rgb>, + reset_colors: Vec<usize>, } impl Handler for MockHandler { @@ -1533,6 +1534,10 @@ mod tests { fn set_color(&mut self, _: usize, c: Rgb) { self.color = Some(c); } + + fn reset_color(&mut self, index: usize) { + self.reset_colors.push(index) + } } impl Default for MockHandler { @@ -1543,6 +1548,7 @@ mod tests { attr: None, identity_reported: false, color: None, + reset_colors: Vec::new(), } } } @@ -1755,4 +1761,48 @@ mod tests { assert_eq!(handler.color, Some(Rgb { r: 0xf0, g: 0xf0, b: 0xf0 })); } + + #[test] + fn parse_osc104_reset_color() { + let bytes: &[u8] = b"\x1b]104;1;\x1b\\"; + + let mut parser = Processor::new(); + let mut handler = MockHandler::default(); + + for byte in bytes { + parser.advance(&mut handler, *byte); + } + + assert_eq!(handler.reset_colors, vec![1]); + } + + #[test] + fn parse_osc104_reset_all_colors() { + let bytes: &[u8] = b"\x1b]104;\x1b\\"; + + let mut parser = Processor::new(); + let mut handler = MockHandler::default(); + + for byte in bytes { + parser.advance(&mut handler, *byte); + } + + let expected: Vec<usize> = (0..256).collect(); + assert_eq!(handler.reset_colors, expected); + } + + #[test] + fn parse_osc104_reset_all_colors_no_semicolon() { + let bytes: &[u8] = b"\x1b]104\x1b\\"; + + let mut parser = Processor::new(); + let mut handler = MockHandler::default(); + + for byte in bytes { + parser.advance(&mut handler, *byte); + } + + let expected: Vec<usize> = (0..256).collect(); + assert_eq!(handler.reset_colors, expected); + } } |