mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-03 06:30:00 -06:00
Reject repeated '#' in perspective grid colour parser
Found while testing crates/tools/src/distort/perspective/define.rs:84-86 (Rgb::parse) 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:
committed by
bflatastic
co-authored by
Claude Haiku 5.5
parent
c0872ff9c6
commit
6664e366e7
@@ -82,7 +82,8 @@ pub struct Rgb(pub [u8; 3]);
|
||||
impl Rgb {
|
||||
/// `#rrggbb` or `rrggbb`.
|
||||
pub fn parse(s: &str) -> Option<Self> {
|
||||
let h = s.trim().trim_start_matches('#');
|
||||
let h = s.trim();
|
||||
let h = h.strip_prefix('#').unwrap_or(h);
|
||||
if h.len() != 6 || !h.chars().all(|c| c.is_ascii_hexdigit()) {
|
||||
return None;
|
||||
}
|
||||
@@ -397,6 +398,15 @@ mod tests {
|
||||
|
||||
const AB: Rect = Rect::new(0.0, 0.0, 800.0, 600.0);
|
||||
|
||||
#[test]
|
||||
fn rgb_rejects_repeated_hash() {
|
||||
assert!(Rgb::parse("##ff0000").is_none());
|
||||
assert!(Rgb::parse("####00ff00").is_none());
|
||||
assert!(Rgb::try_from(String::from("##ff0000")).is_err());
|
||||
assert_eq!(Rgb::parse("#ff0000"), Some(Rgb([255, 0, 0])));
|
||||
assert_eq!(Rgb::parse("ff0000"), Some(Rgb([255, 0, 0])));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_station_point_places_the_vanishing_points() {
|
||||
let mut g = PerspectiveGrid::normal(2, AB);
|
||||
|
||||
Reference in New Issue
Block a user