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:
DaftMouse 2022-01-20 20:57:58 -03:00 committed by GitHub
parent 60ef17e8e9
commit c4d610d5bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions

View File

@ -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

View File

@ -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);
}
}