From 4ccda1aaa5b3a36b641620edf499d03498984021 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Wed, 28 Aug 2019 02:35:34 +0200 Subject: [PATCH] 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. --- alacritty_terminal/src/ansi.rs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs index eb8283a..f95dc35 100644 --- a/alacritty_terminal/src/ansi.rs +++ b/alacritty_terminal/src/ansi.rs @@ -27,11 +27,9 @@ use crate::term::color::Rgb; // Parse colors in XParseColor format fn xparse_color(color: &[u8]) -> Option { 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]