Reject multiple leading '#' in the colour panel hex parser

Found while testing crates/ui-egui/src/panels/color.rs:199-205 (parse_hex)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-31 19:43:17 +07:00
committed by bflatastic
co-authored by Claude Haiku 5.5
parent d0e1a045c1
commit 18709b0b63
2 changed files with 4 additions and 1 deletions
+2 -1
View File
@@ -197,7 +197,8 @@ pub fn hex_digits(c: &Color) -> String {
/// Parse a hex field (`E67828`, `#e67828`, `fff`).
pub fn parse_hex(s: &str) -> Option<Color> {
let s = s.trim().trim_start_matches('#');
let s = s.trim();
let s = s.strip_prefix('#').unwrap_or(s);
if !(s.len() == 3 || s.len() == 6) || !s.chars().all(|c| c.is_ascii_hexdigit()) {
return None;
}
+2
View File
@@ -673,4 +673,6 @@ fn spectrum_and_hex() {
assert_eq!(parse_hex("#fff").unwrap().to_hex(), "#ffffff");
assert!(parse_hex("zz").is_none());
assert!(parse_hex("12345").is_none());
assert!(parse_hex("##e67828").is_none());
assert!(parse_hex("###fff").is_none());
}