summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2019-08-28 02:35:34 +0200
committerChristian Duerr <contact@christianduerr.com>2019-08-28 18:12:10 +0200
commit4ccda1aaa5b3a36b641620edf499d03498984021 (patch)
treeed5fb6433f08273861b77b35c4d9d14304b8819f /alacritty_terminal
parentb6c5f6918c2e4b02ebf78b359fe0a2bde15c21fb (diff)
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.
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/src/ansi.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs
index eb8283a6..f95dc356 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<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]