From 133574ab0900b6f6d262357822f6b5547de47640 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Tue, 14 Jul 2020 23:11:43 +0200 Subject: [PATCH] fix(config): don't panic when hex color is too short (#1473) * fix(config): don't panic when hex color is too short * check length instead of using get --- src/config.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/config.rs b/src/config.rs index be55af0f8..9099011aa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -384,6 +384,10 @@ fn parse_color_string(color_string: &str) -> Option { "Attempting to read hexadecimal color string: {}", color_string ); + if color_string.len() != 7 { + log::debug!("Could not parse hexadecimal string: {}", color_string); + return None; + } let r: u8 = u8::from_str_radix(&color_string[1..3], 16).ok()?; let g: u8 = u8::from_str_radix(&color_string[3..5], 16).ok()?; let b: u8 = u8::from_str_radix(&color_string[5..7], 16).ok()?; @@ -591,6 +595,24 @@ mod tests { assert_eq!(