mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-01 05:37:23 -06:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user