From c2e24a44ac6cd5c85a7eb75be43b72c6acd11520 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:24:46 +0000 Subject: [PATCH] feat: reject a set of invalid inputs for Color::from_hex --- helix-view/src/graphics.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/helix-view/src/graphics.rs b/helix-view/src/graphics.rs index 6ecc8076..fcc037ed 100644 --- a/helix-view/src/graphics.rs +++ b/helix-view/src/graphics.rs @@ -277,6 +277,9 @@ impl Color { /// assert_eq!(color1, color2); /// ``` pub fn from_hex(hex: &str) -> Option { + if !(hex.starts_with('#') && hex.len() == 7) { + return None; + } match [1..=2, 3..=4, 5..=6].map(|i| hex.get(i).and_then(|c| u8::from_str_radix(c, 16).ok())) { [Some(r), Some(g), Some(b)] => Some(Self::Rgb(r, g, b)),