From 9766439890a9fc7f10dc9162f09fa2c2f36143c8 Mon Sep 17 00:00:00 2001 From: Aditya Garud <153842990+yashranaway@users.noreply.github.com> Date: Thu, 22 Oct 2026 07:46:16 +0000 Subject: [PATCH] fix(rendering): avoid panics for non-ascii hex colours --- crates/rendering/src/lib.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs index cfb5df9eac4..78097b36791 100644 --- a/crates/rendering/src/lib.rs +++ b/crates/rendering/src/lib.rs @@ -5235,6 +5235,33 @@ impl ProjectUniforms { mod tests { use super::*; + #[test] + fn color_components_parse_rgb_hex_with_either_case_and_optional_hash() { + for hex in ["#4785FF", "4785ff", "#4785ff"] { + assert_eq!(parse_color_component(hex, 0), 71.0 / 255.0); + assert_eq!(parse_color_component(hex, 1), 133.0 / 255.0); + assert_eq!(parse_color_component(hex, 2), 1.0); + } + } + + #[test] + fn color_components_fall_back_for_unsupported_hex_formats() { + for hex in ["", "#abc", "#abcd", "#12345678", " #123456 ", "#GGHHII"] { + for index in 0..3 { + assert_eq!(parse_color_component(hex, index), 1.0, "{hex:?}"); + } + } + } + + #[test] + fn color_components_fall_back_for_six_byte_unicode_colors() { + for hex in ["#白色", "白色", "#a白bc", "#ab白c", "#abc白", "#💙ab"] { + for index in 0..3 { + assert_eq!(parse_color_component(hex, index), 1.0, "{hex:?}"); + } + } + } + #[test] fn camera_blur_output_rejects_missing_pending_and_failed_masks() { use cap_camera_effects::{BlurFailure, BlurMaskStatus, BlurMode, BlurOutputStatus}; @@ -9045,7 +9072,7 @@ fn blur_mode_from_config( fn parse_color_component(hex_color: &str, index: usize) -> f32 { let color = hex_color.trim_start_matches('#'); - if color.len() == 6 { + if color.len() == 6 && color.is_ascii() { let start = index * 2; if let Ok(value) = u8::from_str_radix(&color[start..start + 2], 16) { return value as f32 / 255.0;