Merge pull request #4805 from Silvertree2010/fix/h4247-color-panel-hex-parser-accepts-s

Reject multiple leading '#' in the colour panel hex parser
This commit is contained in:
BFlat
2026-10-31 20:16:01 +07:00
committed by GitHub
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());
}