Fix legacy xparsecolor regression

The legacy xparsecolor implementation assumed that the \007 ending would
be passed to the parser, however it never is. This caused colors in the
format #rrggbb to be interpreted as #rrggb, leading to incorrect colors
showing up in Alacritty.

Fixes #2759.
This commit is contained in:
Christian Duerr 2019-08-28 02:35:34 +02:00
parent b6c5f6918c
commit 4ccda1aaa5
No known key found for this signature in database
GPG Key ID: 85CDAE3C164BA7B4
1 changed files with 14 additions and 16 deletions

View File

@ -27,11 +27,9 @@ use crate::term::color::Rgb;
// Parse colors in XParseColor format
fn xparse_color(color: &[u8]) -> Option<Rgb> {
if !color.is_empty() && color[0] == b'#' {
let len = color.len().saturating_sub(1);
parse_legacy_color(&color[1..len])
parse_legacy_color(&color[1..])
} else if color.len() >= 4 && &color[..4] == b"rgb:" {
let len = color.len().saturating_sub(1);
parse_rgb_color(&color[4..len])
parse_rgb_color(&color[4..])
} else {
None
}
@ -1613,30 +1611,30 @@ mod tests {
#[test]
fn parse_valid_rgb_colors() {
assert_eq!(xparse_color(b"rgb:f/e/d\x07"), Some(Rgb { r: 0xff, g: 0xee, b: 0xdd }));
assert_eq!(xparse_color(b"rgb:11/aa/ff\x07"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
assert_eq!(xparse_color(b"rgb:f/ed1/cb23\x07"), Some(Rgb { r: 0xff, g: 0xec, b: 0xca }));
assert_eq!(xparse_color(b"rgb:ffff/0/0\x07"), Some(Rgb { r: 0xff, g: 0x0, b: 0x0 }));
assert_eq!(xparse_color(b"rgb:f/e/d"), Some(Rgb { r: 0xff, g: 0xee, b: 0xdd }));
assert_eq!(xparse_color(b"rgb:11/aa/ff"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
assert_eq!(xparse_color(b"rgb:f/ed1/cb23"), Some(Rgb { r: 0xff, g: 0xec, b: 0xca }));
assert_eq!(xparse_color(b"rgb:ffff/0/0"), Some(Rgb { r: 0xff, g: 0x0, b: 0x0 }));
}
#[test]
fn parse_valid_legacy_rgb_colors() {
assert_eq!(xparse_color(b"#1af\x07"), Some(Rgb { r: 0x10, g: 0xa0, b: 0xf0 }));
assert_eq!(xparse_color(b"#11aaff\x07"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
assert_eq!(xparse_color(b"#110aa0ff0\x07"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
assert_eq!(xparse_color(b"#1100aa00ff00\x07"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
assert_eq!(xparse_color(b"#1af"), Some(Rgb { r: 0x10, g: 0xa0, b: 0xf0 }));
assert_eq!(xparse_color(b"#11aaff"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
assert_eq!(xparse_color(b"#110aa0ff0"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
assert_eq!(xparse_color(b"#1100aa00ff00"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
}
#[test]
fn parse_invalid_rgb_colors() {
assert_eq!(xparse_color(b"rgb:0//\x07"), None);
assert_eq!(xparse_color(b"rgb://///\x07"), None);
assert_eq!(xparse_color(b"rgb:0//"), None);
assert_eq!(xparse_color(b"rgb://///"), None);
}
#[test]
fn parse_invalid_legacy_rgb_colors() {
assert_eq!(xparse_color(b"#\x07"), None);
assert_eq!(xparse_color(b"#f\x07"), None);
assert_eq!(xparse_color(b"#"), None);
assert_eq!(xparse_color(b"#f"), None);
}
#[test]