summaryrefslogtreecommitdiff
path: root/alacritty_terminal
diff options
context:
space:
mode:
authorDaftMouse <daftmouse@protonmail.com>2022-01-20 20:57:58 -0300
committerGitHub <noreply@github.com>2022-01-20 23:57:58 +0000
commitc4d610d5bfffa332a4d74b5b67174be73b049c16 (patch)
tree010b682acf166fcdd1b15f4a5390cb115c57e77e /alacritty_terminal
parent60ef17e8e98b0ed219a145881d10ecd6b9f26e85 (diff)
downloadalacritty-c4d610d5bfffa332a4d74b5b67174be73b049c16.tar.gz
alacritty-c4d610d5bfffa332a4d74b5b67174be73b049c16.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.
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/src/ansi.rs52
1 files changed, 51 insertions, 1 deletions
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);
+ }
}