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.
This commit is contained in:
parent
60ef17e8e9
commit
c4d610d5bf
|
@ -19,6 +19,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
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue